atom.io 0.34.1 → 0.35.0

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.
Files changed (53) hide show
  1. package/dist/internal/index.d.ts +32 -41
  2. package/dist/internal/index.d.ts.map +1 -1
  3. package/dist/internal/index.js +106 -128
  4. package/dist/internal/index.js.map +1 -1
  5. package/dist/json/index.d.ts +19 -7
  6. package/dist/json/index.d.ts.map +1 -1
  7. package/dist/json/index.js +4 -0
  8. package/dist/json/index.js.map +1 -1
  9. package/dist/main/index.d.ts +704 -788
  10. package/dist/main/index.d.ts.map +1 -1
  11. package/dist/main/index.js +61 -33
  12. package/dist/main/index.js.map +1 -1
  13. package/dist/react-devtools/index.js +10 -10
  14. package/dist/react-devtools/index.js.map +1 -1
  15. package/dist/realtime/index.d.ts.map +1 -1
  16. package/dist/realtime/index.js +3 -5
  17. package/dist/realtime/index.js.map +1 -1
  18. package/dist/realtime-client/index.js +10 -10
  19. package/dist/realtime-client/index.js.map +1 -1
  20. package/dist/realtime-server/index.d.ts.map +1 -1
  21. package/dist/realtime-server/index.js +8 -10
  22. package/dist/realtime-server/index.js.map +1 -1
  23. package/package.json +12 -12
  24. package/src/internal/atom/create-regular-atom.ts +1 -0
  25. package/src/internal/atom/index.ts +0 -1
  26. package/src/internal/families/index.ts +0 -1
  27. package/src/internal/index.ts +111 -89
  28. package/src/internal/join/join-internal.ts +3 -4
  29. package/src/internal/mutable/create-mutable-atom-family.ts +0 -1
  30. package/src/internal/mutable/create-mutable-atom.ts +1 -1
  31. package/src/internal/selector/register-selector.ts +2 -2
  32. package/src/json/entries.ts +10 -3
  33. package/src/json/index.ts +40 -17
  34. package/src/main/atom.ts +68 -115
  35. package/src/main/dispose-state.ts +0 -2
  36. package/src/main/find-state.ts +3 -9
  37. package/src/main/get-state.ts +0 -2
  38. package/src/main/index.ts +1 -176
  39. package/src/main/join.ts +12 -20
  40. package/src/main/reset-state.ts +0 -2
  41. package/src/main/selector.ts +5 -72
  42. package/src/main/set-state.ts +1 -4
  43. package/src/main/silo.ts +14 -5
  44. package/src/main/subscribe.ts +0 -7
  45. package/src/main/timeline.ts +24 -32
  46. package/src/main/tokens.ts +247 -0
  47. package/src/main/transaction.ts +17 -55
  48. package/src/main/validators.ts +1 -1
  49. package/src/react-devtools/store.ts +61 -45
  50. package/src/realtime/shared-room-store.ts +3 -5
  51. package/src/realtime-server/realtime-server-stores/server-user-store.ts +3 -5
  52. package/src/internal/atom/create-standalone-atom.ts +0 -39
  53. package/src/internal/families/create-atom-family.ts +0 -38
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["random: () => number","scion: T","lengthOrArray: T[] | number","length: number","item: T","token: ReadableFamilyToken<any, any>","key: Canonical","state: AtomIOInternalResource","a: AType","b: BType","key: AType | BType","x: AType | BType","ys: AType[] | BType[]","x: XType","ys: YType[]","a: AType | undefined","b: BType | undefined","contentKey: string","content: Content","data: JunctionSchema<ASide, BSide> &\n\t\t\tPartial<JunctionEntries<NoInfer<AType>, NoInfer<BType>, Content>>","config?: JunctionAdvancedConfiguration<AType, BType, Content>","content: Content | undefined","x:\n\t\t\t| AType\n\t\t\t| BType\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>","b?: AType | BType","singleRelation: AType | BType | undefined","relations: Content extends null ? YType[] : Record<YType, Content>","config?: { reckless: boolean }","input: Record<ASide, AType> | Record<BSide, BType>","a: AType | BType","key: string","subscriber: this[`Subscriber`]","value: T","initialState: T","store: Store","state: ReadableState<T>","store: Store","token: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>","handleUpdate: (update: any) => void","key: string","arbitrary","subscribeToState","subscribeToTransaction","subscribeToTimeline","executor:\n\t\t\t| Promise<T>\n\t\t\t| ((resolve: (value: T) => void, reject: (reason?: any) => void) => void)","superResolve: ((value: T) => void) | undefined","superReject: ((reason?: any) => void) | undefined","promise: Promise<T>","value: T","reason: any","value: Promise<T> | T","target: Store","atom: MutableAtom<T, any>","origin: Store","atom","store: Store","store: Store","token: ReadableToken<any>","key: string","store: Store","atom: Atom<any>","atom","selector: Selector<any>","target: Store","key: string","value: T","subject: Subject<StateUpdate<unknown>>","atom","state: ReadableState<any>","target: Store","state: ReadableState<T>","defaultValue: T","target: Store","selector: Selector<any>","atom: Atom<any>","atom","store: Store","options: RegularAtomFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","individualOptions: RegularAtomOptions<T>","atomFamily","s: Store","store: Store","options:\n\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t| RegularAtomFamilyOptions<T, K>","nextVersionOfThing: Modify<T> | T","originalThing: T","store: Store","state: Atom<T> | Selector<T>","update: StateUpdate<T>","target: Store","atom: Atom<T>","next: T | ((oldValue: T) => T)","atom","atomUpdate: KeyedStateUpdate<T>","transceiver: Transceiver<any>","store: Store","state: Atom<any>","state: WritableState<any>","atom","store: Store","token: ReadableToken<any, any>","store: Store","token: WritableToken<T>","family: WritableFamilyToken<T, Canonical> | null","key: Canonical | null","store: Store","state: WritableState<T>","value: T | ((oldValue: T) => T)","store: Store","token: WritableToken<T>","family: WritableFamilyToken<T, Canonical> | null","key: Canonical | null","value: New | ((oldValue: T) => New)","store: Store","key: string","store: Store","key: string","store: Store","selectorKey: string","covered: Set<string>","atom","store: Store","selectorType:\n\t\t| `readonly_held_selector`\n\t\t| `readonly_pure_selector`\n\t\t| `writable_held_selector`\n\t\t| `writable_pure_selector`","selectorKey: string","dependency: ReadonlyPureSelectorToken<unknown> | WritableToken<unknown>","covered: Set<string>","store: Store","selectorType:\n\t\t| `readonly_held_selector`\n\t\t| `readonly_pure_selector`\n\t\t| `writable_held_selector`\n\t\t| `writable_pure_selector`","selectorKey: string","covered: Set<string>","dependency: ReadableToken<any>","token: WritableToken<T>","value: New | ((oldValue: T) => New)","store: Store","options: ReadonlyHeldSelectorOptions<T>","family: FamilyMetadata | undefined","readonlySelector: ReadonlyHeldSelector<T>","s: Store","token: ReadonlyHeldSelectorToken<T>","store: Store","options: ReadonlyPureSelectorOptions<T>","family: FamilyMetadata | undefined","readonlySelector: ReadonlyPureSelector<T>","s: Store","token: ReadonlyPureSelectorToken<T>","store: Store","string: S","token: AtomIOToken","token: AtomIOToken","store: Store","store: Store","token: TransactionToken<F>","id: string","applying: `newValue` | `oldValue`","atomUpdate: KeyedStateUpdate<any>","store: Store","token: RegularAtomToken<unknown>","error: Error","key: S","store: Store","provenance: A","key: V","dependsOn: `all` | `any`","invalidKeys: stringified<Canonical>[]","creationEvent: MoleculeCreation","type: T","sideA: SingularTypedKey<A>","sideB: SingularTypedKey<B>","compoundKey: CompoundTypedKey<T, A, B>","claim: Claim<V>","join","provenance: stringified<Canonical>[]","values: [string, any][]","disposalEvent: MoleculeDisposal","newProvenance: A","exclusive?: `exclusive`","transferEvent: MoleculeTransfer","update: StateCreation<any>","applying: `newValue` | `oldValue`","store: Store","update: StateDisposal<ReadableToken<any>>","update: StateCreation<any> | StateDisposal<any>","update: MoleculeCreation","update: MoleculeDisposal","update: MoleculeTransfer","applying: `newValue` | `oldValue`","selectorUpdate: TimelineSelectorUpdate<any>","store: Store","applying: `newValue` | `oldValue`","transactionUpdate: TransactionUpdate<any>","store: Store","store: RootStore","transactionKey: string","continuityKey: string","store: Store","store: Store","continuityKey: string","newEpoch: number","transactionKey: string","output: ReturnType<F>","store: Store","store: Store","continuityKey: string","transactionKey: string","store: Store","source: Map<K, V>","key: K","value: V","store: Store","key: string","params: any[]","id: string","childBase: Omit<ChildStore, `transactionMeta`>","transactionMeta: TransactionProgress<Func>","child: ChildStore","store: Store","options: TransactionOptions<F>","newTransaction: Transaction<F>","params: Parameters<F>","id: string","target","store: Store","options: WritableHeldSelectorOptions<T>","family: FamilyMetadata | undefined","next: T | ((oldValue: T) => T)","mySelector: WritableHeldSelector<T>","s: Store","token: WritableHeldSelectorToken<T>","store: Store","options: WritablePureSelectorOptions<T>","family: FamilyMetadata | undefined","next: T | ((oldValue: T) => T)","mySelector: WritablePureSelector<T>","s: Store","token: WritablePureSelectorToken<T>","store: Store","options:\n\t\t| ReadonlyHeldSelectorOptions<any>\n\t\t| ReadonlyPureSelectorOptions<any>\n\t\t| WritableHeldSelectorOptions<any>\n\t\t| WritablePureSelectorOptions<any>","state","store: Store","selectorToken: SelectorToken<unknown>","familyToken: SelectorFamilyToken<any, any>","store: Store","options: ReadonlyPureSelectorFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","s: Store","store: Store","options: ReadonlyHeldSelectorFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","s: Store","store: Store","options: WritableHeldSelectorFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","selectorFamily","s: Store","store: Store","options: WritablePureSelectorFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","selectorFamily","s: Store","store: Store","options:\n\t\t| ReadonlyHeldSelectorFamilyOptions<any, any>\n\t\t| ReadonlyPureSelectorFamilyOptions<any, any>\n\t\t| WritableHeldSelectorFamilyOptions<any, any>\n\t\t| WritablePureSelectorFamilyOptions<any, any>","store: Store","token: ReadableFamilyToken<any, any>","key: Json.Serializable","store: Store","token: ReadableFamilyToken<any, any>","key: Canonical","state: Molecule<any> | ReadableState<any> | undefined","store: Store","token: ReadableFamilyToken<any, any>","key: Canonical","store: Store","token: ReadableToken<any>","store: Store","token: ReadableToken<any>","family: ReadableFamilyToken<any, Canonical> | null","key: Canonical | null","store: Store","token: ReadableToken<T>","key: string","handleUpdate: UpdateHandler<T>","update: StateUpdate<any>","unsubscribe","updateHandler: UpdateHandler<T>","atom","store: Store","token: TimelineToken<ManagedAtom>","key: string","handleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void","store: Store","token: TransactionToken<F>","key: string","handleUpdate: TransactionUpdateHandler<F>","mutableState: MutableAtomToken<Mutable, Json.Serializable>","store: Store","familyMetaData: FamilyMetadata | undefined","mutableState: MutableAtomToken<Mutable, any>","latestUpdateState: RegularAtomToken<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>","target: Store","mutableState: MutableAtomToken<Core, Json.Serializable>","unsubscribe","store: Store","options: MutableAtomOptions<T, J>","family: FamilyMetadata | undefined","newAtom: MutableAtom<T, J>","s: Store","cleanupFunctions: (() => void)[]","handle: UpdateHandler<T>","mutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>","store: Store","store: Store","options: MutableAtomFamilyOptions<T, J, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","individualOptions: MutableAtomOptions<T, J>","atomFamily","s: Store","mutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>","store: Store","jsonFamily: WritablePureSelectorFamily<SerializableCore, Key>","store: Store","mutableAtomToken: MutableAtomToken<Core, SerializableCore>","jsonFamilyToken: WritablePureSelectorFamilyToken<\n\t\t\tSerializableCore,\n\t\t\tstring\n\t\t>","token: WritablePureSelectorToken<SerializableCore>","mutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>","store: Store","updateFamily: AtomFamily<Signal<Core>, Key>","mutableAtomToken: MutableAtomToken<Core, SerializableCore>","updateToken: RegularAtomToken<Signal<Core>>","value: unknown","config: Store[`config`]","store: Store | null","atom","IMPLICIT: { readonly STORE: Store }","store: Store","store: Store","token: AtomIOToken","withdrawn: AtomIOInternalResource | undefined","target: Store | null","store: Store","options: RegularAtomOptions<T>","family: FamilyMetadata | undefined","newAtom: RegularAtom<T>","s: Store","cleanupFunctions: (() => void)[]","handle: UpdateHandler<T>","store: Store","options: MutableAtomOptions<any, any> | RegularAtomOptions<T>","state","store: Store","atomToken: AtomToken<unknown>","atom","atomFamily","disposal: AtomDisposal<AtomToken<unknown>>","tokens: AtomIOToken[]","target: Store","source: Store","store: Store","options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>","defaultContent: Content | undefined","Join","token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>","toolkit: SetterToolkit","run: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void","options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>","defaultContent: Content | undefined","store: Store","aSide: ASide","bSide: BSide","getRelatedKeys: Read<\n\t\t\t(key: string) => SetRTX<AType> | SetRTX<BType>\n\t\t>","addRelation: Write<(a: string, b: string) => void>","deleteRelation: Write<(a: string, b: string) => void>","replaceRelationsSafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t>","previousOwnersToDispose: string[]","replaceRelationsUnsafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t>","has: Read<(a: string, b?: string) => boolean>","baseExternalStoreConfiguration: BaseExternalStoreConfiguration","externalStore: ExternalStoreConfiguration<Content>","contentAtoms: RegularAtomFamilyToken<Content, string>","getContent: Read<(key: string) => Content | null>","setContent: Write<(key: string, content: Content) => void>","contentKey: ContentKey","content: Content","states: JoinStateFamilies<\n\t\t\t\t\tASide,\n\t\t\t\t\tAType,\n\t\t\t\t\tBSide,\n\t\t\t\t\tBType,\n\t\t\t\t\tCardinality,\n\t\t\t\t\tContent\n\t\t\t\t>","token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>","store: Store","token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>","change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void","store: Store","token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>","key: AType | BType","store: Store","relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>","token: JoinToken<any, any, any, any, any, any>","store: Store","value: string","store: Store","options: TimelineOptions<ManagedAtom>","data?: Timeline<ManagedAtom>","tl: Timeline<ManagedAtom>","atomToken: AtomToken<ManagedAtom>","familyToken: AtomFamilyToken<any, any>","token: TimelineToken<ManagedAtom>","atomToken: AtomToken<any>","tl: Timeline<any>","atom","latestUpdate: TimelineUpdate<any> | undefined","atomUpdate: TimelineAtomUpdate<any>","atomFamilyToken: AtomFamilyToken<any, any>","txUpdateInProgress: TransactionUpdate<Func>","currentTxToken: TransactionToken<any>","timelineTransactionUpdate: TimelineTransactionUpdate","updates: TransactionUpdateContent[]","timelineTopics: Set<string>","key: string","familyKey: string | undefined","event: StateCreation<any> | StateDisposal<any>","store: Store","action: `redo` | `undo`","token: TimelineToken<any>"],"sources":["../../src/internal/arbitrary.ts","../../src/internal/lineage.ts","../../src/internal/store/circular-buffer.ts","../../src/internal/store/counterfeit.ts","../../src/internal/store/deposit.ts","../../src/internal/junction.ts","../../src/internal/subject.ts","../../src/internal/subscribe/recall-state.ts","../../src/internal/subscribe/subscribe-in-store.ts","../../src/internal/future.ts","../../src/internal/set-state/copy-mutable-if-needed.ts","../../src/internal/transaction/is-root-store.ts","../../src/internal/operation.ts","../../src/internal/set-state/evict-downstream.ts","../../src/internal/caching.ts","../../src/internal/get-state/read-or-compute-value.ts","../../src/internal/subscribe/subscribe-to-root-atoms.ts","../../src/internal/families/create-regular-atom-family.ts","../../src/internal/families/create-atom-family.ts","../../src/internal/set-state/become.ts","../../src/internal/set-state/emit-update.ts","../../src/internal/set-state/set-atom.ts","../../src/internal/set-state/reset-atom-or-selector.ts","../../src/internal/families/get-family-of-token.ts","../../src/internal/set-state/reset-in-store.ts","../../src/internal/set-state/set-atom-or-selector.ts","../../src/internal/set-state/set-into-store.ts","../../src/internal/keys.ts","../../src/internal/selector/get-selector-dependency-keys.ts","../../src/internal/selector/trace-selector-atoms.ts","../../src/internal/selector/update-selector-atoms.ts","../../src/internal/selector/register-selector.ts","../../src/internal/selector/create-readonly-held-selector.ts","../../src/internal/selector/create-readonly-pure-selector.ts","../../src/internal/transaction/abort-transaction.ts","../../src/internal/capitalize.ts","../../src/internal/pretty-print.ts","../../src/internal/not-found-error.ts","../../src/internal/transaction/act-upon-store.ts","../../src/internal/ingest-updates/ingest-atom-update.ts","../../src/internal/get-trace.ts","../../src/internal/molecule.ts","../../src/internal/ingest-updates/ingest-creation-disposal.ts","../../src/internal/ingest-updates/ingest-selector-update.ts","../../src/internal/ingest-updates/ingest-transaction-update.ts","../../src/internal/transaction/get-epoch-number.ts","../../src/internal/transaction/set-epoch-number.ts","../../src/internal/transaction/apply-transaction.ts","../../src/internal/transaction/assign-transaction-to-continuity.ts","../../src/internal/get-environment-data.ts","../../src/internal/lazy-map.ts","../../src/internal/transaction/build-transaction.ts","../../src/internal/transaction/create-transaction.ts","../../src/internal/transaction/index.ts","../../src/internal/selector/create-writable-held-selector.ts","../../src/internal/selector/create-writable-pure-selector.ts","../../src/internal/selector/create-standalone-selector.ts","../../src/internal/selector/dispose-selector.ts","../../src/internal/families/create-readonly-pure-selector-family.ts","../../src/internal/families/create-readonly-held-selector-family.ts","../../src/internal/families/create-writable-held-selector-family.ts","../../src/internal/families/create-writable-pure-selector-family.ts","../../src/internal/families/create-selector-family.ts","../../src/internal/families/init-family-member.ts","../../src/internal/families/seek-in-store.ts","../../src/internal/families/find-in-store.ts","../../src/internal/families/dispose-from-store.ts","../../src/internal/get-state/get-from-store.ts","../../src/internal/subscribe/subscribe-to-state.ts","../../src/internal/subscribe/subscribe-to-timeline.ts","../../src/internal/subscribe/subscribe-to-transaction.ts","../../src/internal/mutable/tracker.ts","../../src/internal/mutable/create-mutable-atom.ts","../../src/internal/mutable/tracker-family.ts","../../src/internal/mutable/create-mutable-atom-family.ts","../../src/internal/mutable/get-json-family.ts","../../src/internal/mutable/get-json-token.ts","../../src/internal/mutable/get-update-family.ts","../../src/internal/mutable/get-update-token.ts","../../src/internal/mutable/transceiver.ts","../../src/internal/store/store.ts","../../src/internal/store/withdraw.ts","../../src/internal/atom/create-regular-atom.ts","../../src/internal/atom/create-standalone-atom.ts","../../src/internal/atom/dispose-atom.ts","../../src/internal/install-into-store.ts","../../src/internal/join/create-join.ts","../../src/internal/join/join-internal.ts","../../src/internal/join/get-join.ts","../../src/internal/join/edit-relations-in-store.ts","../../src/internal/join/find-relations-in-store.ts","../../src/internal/join/get-internal-relations-from-store.ts","../../src/internal/reserved-keys.ts","../../src/internal/timeline/create-timeline.ts","../../src/internal/timeline/time-travel.ts"],"sourcesContent":["export function arbitrary(random: () => number = Math.random): string {\n\treturn random().toString(36).slice(2)\n}\n","/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\nexport interface Lineage {\n\tparent: typeof this | null\n\tchild: typeof this | null\n}\n\nexport function newest<T extends Lineage>(scion: T): T {\n\twhile (scion.child !== null) {\n\t\tscion = scion.child\n\t}\n\treturn scion\n}\n","export class CircularBuffer<T> {\n\tprotected _buffer: T[]\n\tprotected _index = 0\n\tpublic constructor(array: T[])\n\tpublic constructor(length: number)\n\tpublic constructor(lengthOrArray: T[] | number) {\n\t\tlet length: number\n\t\tif (typeof lengthOrArray === `number`) {\n\t\t\tlength = lengthOrArray\n\t\t} else {\n\t\t\tlength = lengthOrArray.length\n\t\t}\n\t\tthis._buffer = Array.from({ length })\n\t}\n\n\tpublic get buffer(): ReadonlyArray<T | undefined> {\n\t\treturn this._buffer\n\t}\n\n\tpublic get index(): number {\n\t\treturn this._index\n\t}\n\n\tpublic add(item: T): void {\n\t\tthis._buffer[this._index] = item\n\t\tthis._index = (this._index + 1) % this._buffer.length\n\t}\n\n\tpublic copy(): CircularBuffer<T> {\n\t\tconst copy = new CircularBuffer<T>([...this._buffer])\n\t\tcopy._index = this._index\n\t\treturn copy\n\t}\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\n\nexport const FAMILY_MEMBER_TOKEN_TYPES = {\n\tatom_family: `atom`,\n\tmolecule_family: `molecule`,\n\tmutable_atom_family: `mutable_atom`,\n\treadonly_held_selector_family: `readonly_held_selector`,\n\treadonly_pure_selector_family: `readonly_pure_selector`,\n\twritable_held_selector_family: `writable_held_selector`,\n\twritable_pure_selector_family: `writable_pure_selector`,\n} as const\n\nexport function counterfeit<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n\tKey extends K,\n>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n): AtomToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritablePureSelectorToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n): SelectorToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T>\n\nexport function counterfeit(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n): ReadableToken<any> {\n\tconst subKey = stringifyJson(key)\n\tconst fullKey = `${token.key}(${subKey})`\n\tconst type = FAMILY_MEMBER_TOKEN_TYPES[token.type]\n\tconst stateToken = {\n\t\tkey: fullKey,\n\t\ttype,\n\t} satisfies ReadableToken<any>\n\n\tObject.assign(stateToken, {\n\t\tfamily: {\n\t\t\tkey: token.key,\n\t\t\tsubKey,\n\t\t},\n\t})\n\n\tObject.assign(stateToken, { counterfeit: true })\n\treturn stateToken\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomIOToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tFunc,\n\tMutableAtom,\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadableState,\n\tReadonlyPureSelector,\n\tReadonlyPureSelectorFamily,\n\tRegularAtom,\n\tRegularAtomFamily,\n\tSelector,\n\tSelectorFamily,\n\tTimeline,\n\tTransceiver,\n\tWritableFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableState,\n} from \"..\"\nimport type { Transaction } from \"../transaction\"\n\nexport function deposit<T>(state: RegularAtom<T>): RegularAtomToken<T>\nexport function deposit<T extends Transceiver<any>>(\n\tstate: MutableAtom<T, any>,\n): MutableAtomToken<T, any>\nexport function deposit<T>(state: Atom<T>): AtomToken<T>\nexport function deposit<T>(\n\tstate: WritablePureSelector<T>,\n): WritablePureSelectorToken<T>\nexport function deposit<T>(\n\tstate: ReadonlyPureSelector<T>,\n): ReadonlyPureSelectorToken<T>\nexport function deposit<T>(state: Selector<T>): SelectorToken<T>\nexport function deposit<T>(state: WritableState<T>): WritableToken<T>\nexport function deposit<T>(state: ReadableState<T>): ReadableToken<T>\n\nexport function deposit<T, K extends Canonical>(\n\tstate: RegularAtomFamily<T, K>,\n): RegularAtomFamilyToken<T, K>\nexport function deposit<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(state: MutableAtomFamily<T, J, K>): MutableAtomFamilyToken<T, J, K>\nexport function deposit<T>(state: AtomFamily<T, any>): AtomFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: WritablePureSelectorFamily<T, any>,\n): WritablePureSelectorFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: ReadonlyPureSelectorFamily<T, any>,\n): ReadonlyPureSelectorFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: SelectorFamily<T, any>,\n): SelectorFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: WritableFamily<T, any>,\n): WritableFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: ReadableFamily<T, any>,\n): ReadableFamilyToken<T, any>\n\nexport function deposit<T extends Func>(\n\tstate: Transaction<T>,\n): TransactionToken<T>\nexport function deposit<M extends TimelineManageable>(\n\tstate: Timeline<M>,\n): TimelineToken<M>\n\nexport function deposit(resource: AtomIOInternalResource): AtomIOToken\n\nexport function deposit(state: AtomIOInternalResource): AtomIOToken {\n\tconst token = {\n\t\tkey: state.key,\n\t\ttype: state.type,\n\t} as any\n\tif (`family` in state) {\n\t\ttoken.family = state.family\n\t}\n\treturn token\n}\n","import type { Json } from \"atom.io/json\"\n\nimport type { Refinement } from \"./utility-types\"\n\nexport type JunctionEntriesBase<\n\tAType extends string,\n\tBType extends string,\n\tContent extends Json.Object | null,\n> = {\n\treadonly relations: ([AType, BType[]] | [BType, AType[]])[]\n\treadonly contents: [string, Content][]\n}\nexport interface JunctionEntries<\n\tAType extends string,\n\tBType extends string,\n\tContent extends Json.Object | null,\n> extends Json.Object,\n\t\tJunctionEntriesBase<AType, BType, Content> {}\n\nexport type JunctionSchemaBase<ASide extends string, BSide extends string> = {\n\t/** Description of the relationship between the two sides */\n\treadonly between: [a: ASide, b: BSide]\n\t/** How many relations are allowed in each direction? */\n\treadonly cardinality: `1:1` | `1:n` | `n:n`\n}\nexport interface JunctionSchema<ASide extends string, BSide extends string>\n\textends Json.Object,\n\t\tJunctionSchemaBase<ASide, BSide> {}\n\nexport type BaseExternalStoreConfiguration = {\n\taddRelation: (a: string, b: string) => void\n\tdeleteRelation: (a: string, b: string) => void\n\treplaceRelationsSafely: (a: string, bs: string[]) => void\n\treplaceRelationsUnsafely: (a: string, bs: string[]) => void\n\tgetRelatedKeys(key: string): Set<string> | undefined\n\thas: (a: string, b?: string) => boolean\n}\n\nexport type ExternalStoreWithContentConfiguration<Content extends Json.Object> =\n\t{\n\t\tgetContent: (contentKey: string) => Content | undefined\n\t\tsetContent: (contentKey: string, content: Content) => void\n\t\tdeleteContent: (contentKey: string) => void\n\t}\n\nexport type Empty<Obj extends object> = {\n\t[Key in keyof Obj]?: undefined\n}\n\nexport type ExternalStoreConfiguration<Content extends Json.Object | null> =\n\tContent extends Json.Object\n\t\t? BaseExternalStoreConfiguration &\n\t\t\t\tExternalStoreWithContentConfiguration<Content>\n\t\t: BaseExternalStoreConfiguration &\n\t\t\t\tEmpty<ExternalStoreWithContentConfiguration<Json.Object>>\n\nexport type JunctionAdvancedConfiguration<\n\tAType extends string,\n\tBType extends string,\n\tContent extends Json.Object | null,\n> = {\n\twarn?: (...args: any[]) => void\n\texternalStore?: ExternalStoreConfiguration<Content>\n\tisAType?: Refinement<string, AType>\n\tisBType?: Refinement<string, BType>\n\tisContent?: Refinement<unknown, Content>\n\tmakeContentKey?: (a: AType, b: BType) => string\n}\n\nexport type JunctionJSON<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tContent extends Json.Object | null,\n> = JunctionEntries<AType, BType, Content> & JunctionSchema<ASide, BSide>\n\nexport class Junction<\n\tconst ASide extends string,\n\tconst AType extends string,\n\tconst BSide extends string,\n\tconst BType extends string,\n\tconst Content extends Json.Object | null = null,\n> {\n\tpublic readonly a: ASide\n\tpublic readonly b: BSide\n\tpublic readonly cardinality: `1:1` | `1:n` | `n:n`\n\tpublic readonly relations: Map<AType | BType, Set<AType> | Set<BType>> =\n\t\tnew Map()\n\tpublic readonly contents: Map<string, Content> = new Map()\n\n\tpublic isAType?: Refinement<string, AType> | null\n\tpublic isBType?: Refinement<string, BType> | null\n\tpublic isContent: Refinement<unknown, Content> | null\n\tpublic makeContentKey = (a: AType, b: BType): string => `${a}:${b}`\n\n\tpublic warn?: (...args: any[]) => void\n\n\tpublic getRelatedKeys(key: AType): Set<BType> | undefined\n\tpublic getRelatedKeys(key: BType): Set<AType> | undefined\n\tpublic getRelatedKeys(key: AType | BType): Set<AType> | Set<BType> | undefined\n\tpublic getRelatedKeys(\n\t\tkey: AType | BType,\n\t): Set<AType> | Set<BType> | undefined {\n\t\treturn this.relations.get(key)\n\t}\n\tprotected addRelation(a: AType, b: BType): void {\n\t\tlet aRelations = this.relations.get(a) as Set<BType> | undefined\n\t\tlet bRelations = this.relations.get(b) as Set<AType> | undefined\n\t\tif (aRelations) {\n\t\t\taRelations.add(b)\n\t\t} else {\n\t\t\taRelations = new Set([b])\n\t\t\tthis.relations.set(a, aRelations)\n\t\t}\n\t\tif (bRelations) {\n\t\t\tbRelations.add(a)\n\t\t} else {\n\t\t\tbRelations = new Set([a])\n\t\t\tthis.relations.set(b, bRelations)\n\t\t}\n\t}\n\tprotected deleteRelation(a: AType, b: BType): void {\n\t\tconst aRelations = this.relations.get(a) as Set<BType> | undefined\n\t\tif (aRelations) {\n\t\t\taRelations.delete(b)\n\t\t\tif (aRelations.size === 0) {\n\t\t\t\tthis.relations.delete(a)\n\t\t\t}\n\t\t\tconst bRelations = this.relations.get(b) as Set<AType> | undefined\n\t\t\tif (bRelations) {\n\t\t\t\tbRelations.delete(a)\n\t\t\t\tif (bRelations.size === 0) {\n\t\t\t\t\tthis.relations.delete(b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected replaceRelationsUnsafely(a: AType, bs: BType[]): void\n\tprotected replaceRelationsUnsafely(b: BType, as: AType[]): void\n\tprotected replaceRelationsUnsafely(\n\t\tx: AType | BType,\n\t\tys: AType[] | BType[],\n\t): void {\n\t\tthis.relations.set(x as AType, new Set(ys as BType[]))\n\t\tfor (const y of ys) {\n\t\t\tconst yRelations = new Set<AType>().add(x as AType)\n\t\t\tthis.relations.set(y, yRelations)\n\t\t}\n\t}\n\tprotected replaceRelationsSafely(a: AType, bs: BType[]): void\n\tprotected replaceRelationsSafely(b: BType, as: AType[]): void\n\tprotected replaceRelationsSafely<\n\t\tXType extends AType | BType,\n\t\tYType extends XType extends AType ? BType : AType,\n\t>(x: XType, ys: YType[]): void {\n\t\tconst xRelationsPrev = this.relations.get(x)\n\t\tlet a: AType | undefined = this.isAType?.(x) ? x : undefined\n\t\tlet b: BType | undefined = a === undefined ? (x as BType) : undefined\n\t\tif (xRelationsPrev) {\n\t\t\tfor (const y of xRelationsPrev) {\n\t\t\t\ta ??= y as AType\n\t\t\t\tb ??= y as BType\n\t\t\t\tconst yRelations = this.relations.get(y) as Set<XType> | undefined\n\t\t\t\tif (yRelations) {\n\t\t\t\t\tif (yRelations.size === 1) {\n\t\t\t\t\t\tthis.relations.delete(y)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tyRelations.delete(x)\n\t\t\t\t\t}\n\t\t\t\t\tthis.contents.delete(this.makeContentKey(a, b))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.relations.set(x, new Set(ys) as any)\n\t\tfor (const y of ys) {\n\t\t\tlet yRelations = this.relations.get(y) as Set<XType> | undefined\n\t\t\tif (yRelations) {\n\t\t\t\tyRelations.add(x)\n\t\t\t} else {\n\t\t\t\tyRelations = new Set<XType>().add(x)\n\t\t\t\tthis.relations.set(y, yRelations as any)\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected getContentInternal(contentKey: string): Content | undefined {\n\t\treturn this.contents.get(contentKey)\n\t}\n\tprotected setContent(contentKey: string, content: Content): void {\n\t\tthis.contents.set(contentKey, content)\n\t}\n\tprotected deleteContent(contentKey: string): void {\n\t\tthis.contents.delete(contentKey)\n\t}\n\n\tpublic constructor(\n\t\tdata: JunctionSchema<ASide, BSide> &\n\t\t\tPartial<JunctionEntries<NoInfer<AType>, NoInfer<BType>, Content>>,\n\t\tconfig?: JunctionAdvancedConfiguration<AType, BType, Content>,\n\t) {\n\t\tthis.a = data.between[0]\n\t\tthis.b = data.between[1]\n\n\t\tthis.cardinality = data.cardinality\n\t\tif (!config?.externalStore) {\n\t\t\tthis.relations = new Map(\n\t\t\t\tdata.relations?.map(([x, ys]) => [x, new Set(ys as AType[])]),\n\t\t\t)\n\t\t\tthis.contents = new Map(data.contents)\n\t\t}\n\t\tthis.isAType = config?.isAType ?? null\n\t\tthis.isBType = config?.isBType ?? null\n\t\tthis.isContent = config?.isContent ?? null\n\t\tif (config?.makeContentKey) {\n\t\t\tthis.makeContentKey = config.makeContentKey\n\t\t}\n\t\tif (config?.externalStore) {\n\t\t\tconst externalStore = config.externalStore\n\t\t\tthis.has = (a, b) => externalStore.has(a, b)\n\t\t\tthis.addRelation = (a, b) => {\n\t\t\t\texternalStore.addRelation(a, b)\n\t\t\t}\n\t\t\tthis.deleteRelation = (a, b) => {\n\t\t\t\texternalStore.deleteRelation(a, b)\n\t\t\t}\n\t\t\tthis.replaceRelationsSafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsSafely(a, bs)\n\t\t\t}\n\t\t\tthis.replaceRelationsUnsafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsUnsafely(a, bs)\n\t\t\t}\n\t\t\tthis.getRelatedKeys = ((key) =>\n\t\t\t\texternalStore.getRelatedKeys(\n\t\t\t\t\tkey,\n\t\t\t\t)) as typeof Junction.prototype.getRelatedKeys\n\t\t\tif (externalStore.getContent) {\n\t\t\t\tthis.getContentInternal = (contentKey) => {\n\t\t\t\t\treturn externalStore.getContent(contentKey) as any\n\t\t\t\t}\n\t\t\t\tthis.setContent = (contentKey, content) => {\n\t\t\t\t\texternalStore.setContent(contentKey, content as any)\n\t\t\t\t}\n\t\t\t\tthis.deleteContent = (contentKey) => {\n\t\t\t\t\texternalStore.deleteContent(contentKey)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [x, ys] of data.relations ?? []) {\n\t\t\t\tlet a = this.isAType?.(x) ? x : undefined\n\t\t\t\tlet b = a === undefined ? (x as BType) : undefined\n\t\t\t\tfor (const y of ys) {\n\t\t\t\t\ta ??= y as AType\n\t\t\t\t\tb ??= y as BType\n\t\t\t\t\tthis.addRelation(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [contentKey, content] of data.contents ?? []) {\n\t\t\t\tthis.setContent(contentKey, content)\n\t\t\t}\n\t\t}\n\t\tif (config?.warn) {\n\t\t\tthis.warn = config.warn\n\t\t}\n\t}\n\tpublic toJSON(): JunctionJSON<ASide, AType, BSide, BType, Content> {\n\t\treturn {\n\t\t\tbetween: [this.a, this.b],\n\t\t\tcardinality: this.cardinality,\n\t\t\trelations: [...this.relations.entries()].map(\n\t\t\t\t([a, b]) => [a, [...b]] as [AType, BType[]],\n\t\t\t),\n\t\t\tcontents: [...this.contents.entries()],\n\t\t}\n\t}\n\n\tpublic set(\n\t\ta: AType,\n\t\t...rest: Content extends null ? [b: BType] : [b: BType, content: Content]\n\t): this\n\tpublic set(\n\t\trelation: { [Key in ASide]: AType } & { [Key in BSide]: BType },\n\t\t...rest: Content extends null ? [] | [void?: undefined] : [content: Content]\n\t): this\n\tpublic set(\n\t\t// a: AType | ({ [Key in ASide]: AType } & { [Key in BSide]: BType }),\n\t\t// ...rest: Content extends null\n\t\t// \t? [] | [b?: BType | undefined]\n\t\t// \t: [b: BType, content: Content] | [content: Content]\n\t\t...params:\n\t\t\t| [\n\t\t\t\t\ta: AType,\n\t\t\t\t\t...rest: Content extends null\n\t\t\t\t\t\t? [b: BType]\n\t\t\t\t\t\t: [b: BType, content: Content],\n\t\t\t ]\n\t\t\t| [\n\t\t\t\t\trelation: { [Key in ASide]: AType } & { [Key in BSide]: BType },\n\t\t\t\t\t...rest: Content extends null\n\t\t\t\t\t\t? [] | [void?: undefined]\n\t\t\t\t\t\t: [content: Content],\n\t\t\t ]\n\t\t// | [{ [Key in ASide]: AType } & { [Key in BSide]: BType }, content: Content]\n\t\t// | [{ [Key in ASide]: AType } & { [Key in BSide]: BType }]\n\t\t// | [a: AType, b: BType, content: Content]\n\t\t// | [a: AType, b: BType]\n\t): this {\n\t\tlet a: AType\n\t\tlet b: BType\n\t\tlet content: Content | undefined\n\t\tswitch (params.length) {\n\t\t\tcase 1: {\n\t\t\t\tconst relation = params[0] as Record<ASide, AType> & Record<BSide, BType>\n\t\t\t\ta = relation[this.a]\n\t\t\t\tb = relation[this.b]\n\t\t\t\tcontent = undefined\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 2: {\n\t\t\t\tconst zeroth = params[0]\n\t\t\t\tif (typeof zeroth === `string`) {\n\t\t\t\t\t;[a, b] = params as unknown as [AType, BType]\n\t\t\t\t} else {\n\t\t\t\t\ta = zeroth[this.a]\n\t\t\t\t\tb = zeroth[this.b]\n\t\t\t\t\tcontent = params[1] as Content\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\ta = params[0] as AType\n\t\t\t\tb = params[1] as BType\n\t\t\t\tcontent = params[2] as Content\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (this.cardinality) {\n\t\t\t// biome-ignore lint/suspicious/noFallthroughSwitchClause: perfect here\n\t\t\tcase `1:1`: {\n\t\t\t\tconst bPrev = this.getRelatedKey(a)\n\t\t\t\tif (bPrev && bPrev !== b) this.delete(a, bPrev)\n\t\t\t}\n\t\t\tcase `1:n`:\n\t\t\t\t{\n\t\t\t\t\tconst aPrev = this.getRelatedKey(b)\n\t\t\t\t\tif (aPrev && aPrev !== a) this.delete(aPrev, b)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `n:n`: // do nothing\n\t\t}\n\t\tif (content) {\n\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\tthis.setContent(contentKey, content)\n\t\t}\n\t\tthis.addRelation(a, b)\n\t\treturn this\n\t}\n\n\tpublic delete(a: AType, b?: BType): this\n\tpublic delete(b: BType, a?: AType): this\n\tpublic delete(\n\t\trelation:\n\t\t\t| { [Key in ASide]: AType }\n\t\t\t| { [Key in BSide]: BType }\n\t\t\t| ({ [Key in ASide]: AType } & { [Key in BSide]: BType }),\n\t\tb?: undefined,\n\t): this\n\tpublic delete(\n\t\tx:\n\t\t\t| AType\n\t\t\t| BType\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>,\n\t\tb?: AType | BType,\n\t): this {\n\t\t// @ts-expect-error we deduce that this.b may index x\n\t\tb = typeof b === `string` ? (b as BType) : (x[this.b] as BType | undefined)\n\t\tconst a =\n\t\t\t// @ts-expect-error we deduce that this.a may index x\n\t\t\ttypeof x === `string` ? (x as AType) : (x[this.a] as AType | undefined)\n\n\t\tif (a === undefined && typeof b === `string`) {\n\t\t\tconst bRelations = this.getRelatedKeys(b) as Set<AType>\n\t\t\tif (bRelations) {\n\t\t\t\tfor (const bRelation of bRelations) {\n\t\t\t\t\tthis.delete(bRelation, b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && b === undefined) {\n\t\t\tconst aRelations = this.getRelatedKeys(a)\n\t\t\tif (aRelations) {\n\t\t\t\tfor (const aRelation of aRelations) {\n\t\t\t\t\tthis.delete(a, aRelation)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && typeof b === `string`) {\n\t\t\tthis.deleteRelation(a, b)\n\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\tthis.deleteContent(contentKey)\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic getRelatedKey(key: AType): BType | undefined\n\tpublic getRelatedKey(key: BType): AType | undefined\n\tpublic getRelatedKey(key: AType | BType): AType | BType | undefined {\n\t\tconst relations = this.getRelatedKeys(key)\n\t\tif (relations) {\n\t\t\tif (relations.size > 1) {\n\t\t\t\tthis.warn?.(\n\t\t\t\t\t`${relations.size} related keys were found for key \"${key}\": (${[\n\t\t\t\t\t\t...relations,\n\t\t\t\t\t]\n\t\t\t\t\t\t.map((k) => `\"${k}\"`)\n\t\t\t\t\t\t.join(`, `)}). Only one related key was expected.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tlet singleRelation: AType | BType | undefined\n\t\t\tfor (const relation of relations) {\n\t\t\t\tsingleRelation = relation\n\t\t\t\tbreak\n\t\t\t}\n\t\t\treturn singleRelation\n\t\t}\n\t}\n\n\tpublic replaceRelations(\n\t\ta: AType,\n\t\trelations: Content extends null ? BType[] : Record<BType, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this\n\tpublic replaceRelations(\n\t\tb: BType,\n\t\trelations: Content extends null ? AType[] : Record<AType, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this\n\tpublic replaceRelations<\n\t\tXType extends AType | BType,\n\t\tYType extends XType extends AType ? BType : AType,\n\t>(\n\t\tx: XType,\n\t\trelations: Content extends null ? YType[] : Record<YType, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this {\n\t\tconst hasContent = !Array.isArray(relations)\n\t\tconst ys = (hasContent ? Object.keys(relations) : relations) as YType[]\n\t\tif (config?.reckless) {\n\t\t\tthis.replaceRelationsUnsafely(x as any, ys as any)\n\t\t} else {\n\t\t\tthis.replaceRelationsSafely(x as any, ys as any)\n\t\t}\n\t\tif (hasContent) {\n\t\t\tfor (const y of ys) {\n\t\t\t\tconst contentKey = this.makeContentKey(x as any, y as any) // sort XY to AB ❗\n\t\t\t\tconst content = (relations as Record<YType, Content>)[y]\n\t\t\t\tthis.setContent(contentKey, content)\n\t\t\t}\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic getContent(a: AType, b: BType): Content | undefined {\n\t\tconst contentKey = this.makeContentKey(a, b)\n\t\treturn this.getContentInternal(contentKey)\n\t}\n\n\tpublic getRelationEntries(input: Record<ASide, AType>): [BType, Content][]\n\tpublic getRelationEntries(input: Record<BSide, BType>): [AType, Content][]\n\tpublic getRelationEntries(\n\t\tinput: Record<ASide, AType> | Record<BSide, BType>,\n\t): [AType | BType, Content][] {\n\t\tconst a: AType | undefined = (input as any)[this.a]\n\t\tconst b: BType | undefined = (input as any)[this.b]\n\t\tif (a !== undefined && b === undefined) {\n\t\t\tconst aRelations = this.getRelatedKeys(a)\n\t\t\tif (aRelations) {\n\t\t\t\treturn [...aRelations].map((aRelation) => {\n\t\t\t\t\treturn [aRelation, this.getContent(a, aRelation) as Content]\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\tif (a === undefined && b !== undefined) {\n\t\t\tconst bRelations = this.getRelatedKeys(b)\n\t\t\tif (bRelations) {\n\t\t\t\treturn [...bRelations].map((bRelation) => {\n\t\t\t\t\treturn [bRelation, this.getContent(bRelation, b) as Content]\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn []\n\t}\n\n\tpublic has(a: AType, b?: BType): boolean\n\tpublic has(b: BType, a?: AType): boolean\n\tpublic has(a: AType | BType, b?: AType | BType): boolean {\n\t\tif (b) {\n\t\t\tconst setA = this.getRelatedKeys(a)\n\t\t\treturn setA?.has(b as any) ?? false\n\t\t}\n\t\treturn this.relations.has(a)\n\t}\n}\n","export class Subject<T> {\n\tpublic Subscriber!: (value: T) => void\n\n\tpublic subscribers: Map<string, this[`Subscriber`]> = new Map()\n\n\tpublic subscribe(key: string, subscriber: this[`Subscriber`]): () => void {\n\t\tthis.subscribers.set(key, subscriber)\n\t\tconst unsubscribe = () => {\n\t\t\tthis.unsubscribe(key)\n\t\t}\n\t\treturn unsubscribe\n\t}\n\n\tprivate unsubscribe(key: string) {\n\t\tthis.subscribers.delete(key)\n\t}\n\n\tpublic next(value: T): void {\n\t\tconst subscribers = this.subscribers.values()\n\t\tfor (const subscriber of subscribers) {\n\t\t\tsubscriber(value)\n\t\t}\n\t}\n}\n\nexport class StatefulSubject<T> extends Subject<T> {\n\tpublic state: T\n\n\tpublic constructor(initialState: T) {\n\t\tsuper()\n\t\tthis.state = initialState\n\t}\n\n\tpublic next(value: T): void {\n\t\tthis.state = value\n\t\tsuper.next(value)\n\t}\n}\n","import type { ReadableState } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const recallState = <T>(store: Store, state: ReadableState<T>): T => {\n\tconst target = newest(store)\n\tif (target.operation.open) {\n\t\treturn target.operation.prev.get(state.key)\n\t}\n\treturn target.valueMap.get(state.key)\n}\n","import type {\n\tReadableToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdateHandler,\n\tUpdateHandler,\n} from \"atom.io\"\nimport type { Func, Store } from \"atom.io/internal\"\nimport {\n\tarbitrary,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nexport function subscribeInStore<T>(\n\tstore: Store,\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n): () => void\nexport function subscribeInStore<F extends Func>(\n\tstore: Store,\n\ttoken: TransactionToken<F>,\n\thandleUpdate: TransactionUpdateHandler<F>,\n\tkey?: string,\n): () => void\nexport function subscribeInStore<M extends TimelineManageable>(\n\tstore: Store,\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n): () => void\nexport function subscribeInStore<M extends TimelineManageable>(\n\tstore: Store,\n\ttoken: ReadableToken<any> | TimelineToken<M> | TransactionToken<any>,\n\thandleUpdate:\n\t\t| TransactionUpdateHandler<any>\n\t\t| UpdateHandler<any>\n\t\t| ((update: TimelineUpdate<M> | `redo` | `undo`) => void),\n\tkey?: string,\n): () => void\nexport function subscribeInStore(\n\tstore: Store,\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = arbitrary(),\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `readonly_held_selector`:\n\t\tcase `writable_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\treturn subscribeToState(store, token, key, handleUpdate)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(store, token, key, handleUpdate)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(store, token, key, handleUpdate)\n\t}\n}\n","/**\n * A Promise whose incoming value can be hot swapped.\n * @internal\n * @private\n * @typeParam T The type of the value that the promise will resolve to.\n *\n * @remarks\n * Can be constructed like a Promise, or from an existing Promise.\n */\nexport class Future<T> extends Promise<T> {\n\tprivate fate: Promise<T> | undefined\n\tprivate resolve: (value: T) => void\n\tprivate reject: (reason?: any) => void\n\n\tpublic done = false\n\n\tpublic constructor(\n\t\texecutor:\n\t\t\t| Promise<T>\n\t\t\t| ((resolve: (value: T) => void, reject: (reason?: any) => void) => void),\n\t) {\n\t\tlet superResolve: ((value: T) => void) | undefined\n\t\tlet superReject: ((reason?: any) => void) | undefined\n\t\tsuper((resolve, reject) => {\n\t\t\tsuperResolve = resolve\n\t\t\tsuperReject = reject\n\t\t})\n\t\tthis.resolve = superResolve as (value: T) => void\n\t\tthis.reject = superReject as (reason?: any) => void\n\t\tthis.use(executor instanceof Promise ? executor : new Promise(executor))\n\t}\n\n\tprivate pass(promise: Promise<T>, value: T) {\n\t\tif (promise === this.fate) {\n\t\t\tthis.resolve(value)\n\t\t\tthis.done = true\n\t\t}\n\t}\n\tprivate fail(promise: Promise<T>, reason: any) {\n\t\tif (promise === this.fate) {\n\t\t\tthis.reject(reason)\n\t\t\tthis.done = true\n\t\t}\n\t}\n\n\tpublic use(value: Promise<T> | T): void {\n\t\tif (this === value) {\n\t\t\treturn\n\t\t}\n\t\tif (value instanceof Promise) {\n\t\t\tconst promise = value\n\t\t\tthis.fate = promise\n\t\t\tpromise.then(\n\t\t\t\t(resolved) => {\n\t\t\t\t\tthis.pass(promise, resolved)\n\t\t\t\t},\n\t\t\t\t(reason) => {\n\t\t\t\t\tthis.fail(promise, reason)\n\t\t\t\t},\n\t\t\t)\n\t\t} else {\n\t\t\tthis.resolve(value)\n\t\t\tthis.fate = undefined\n\t\t}\n\t}\n}\n","import type { MutableAtom, Transceiver } from \"..\"\nimport { Tracker } from \"../mutable\"\nimport type { Store } from \"../store\"\n\nexport function copyMutableIfNeeded<T extends Transceiver<any>>(\n\ttarget: Store,\n\tatom: MutableAtom<T, any>,\n\torigin: Store,\n): T {\n\tconst originValue = origin.valueMap.get(atom.key)\n\tconst targetValue = target.valueMap.get(atom.key)\n\n\tif (originValue !== targetValue) {\n\t\treturn targetValue\n\t}\n\n\tif (originValue === undefined) {\n\t\treturn atom.default()\n\t}\n\n\torigin.logger.info(`📃`, `atom`, atom.key, `copying`)\n\tconst jsonValue = atom.toJson(originValue)\n\tconst copiedValue = atom.fromJson(jsonValue)\n\ttarget.valueMap.set(atom.key, copiedValue)\n\tnew Tracker(atom, origin)\n\treturn copiedValue\n}\n","import type { Store } from \"../store\"\nimport type { Func } from \"../utility-types\"\nimport type { TransactionEpoch, TransactionProgress } from \".\"\n\nexport interface RootStore extends Store {\n\ttransactionMeta: TransactionEpoch\n\tparent: null\n\tchild: ChildStore | null\n}\nexport interface ChildStore extends Store {\n\ttransactionMeta: TransactionProgress<Func>\n\tparent: ChildStore | RootStore\n\tchild: ChildStore | null\n}\n\nexport function isRootStore(store: Store): store is RootStore {\n\treturn `epoch` in store.transactionMeta\n}\n\nexport function isChildStore(store: Store): store is ChildStore {\n\treturn `phase` in store.transactionMeta\n}\n","import type { ReadableToken } from \"atom.io\"\n\nimport type { Store } from \"./store\"\nimport { isChildStore } from \"./transaction/is-root-store\"\n\nexport type OperationProgress =\n\t| {\n\t\t\topen: false\n\t }\n\t| {\n\t\t\topen: true\n\t\t\tdone: Set<string>\n\t\t\tprev: Map<string, any>\n\t\t\ttime: number\n\t\t\ttoken: ReadableToken<any>\n\t }\n\nexport const openOperation = (\n\tstore: Store,\n\ttoken: ReadableToken<any>,\n): number | undefined => {\n\tif (store.operation.open) {\n\t\tconst rejectionTime = performance.now()\n\t\tstore.logger.info(\n\t\t\t`❗`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`deferring setState at T-${rejectionTime} until setState for \"${store.operation.token.key}\" is done`,\n\t\t)\n\t\treturn rejectionTime\n\t}\n\tstore.operation = {\n\t\topen: true,\n\t\tdone: new Set(),\n\t\tprev: new Map(),\n\t\ttime: Date.now(),\n\t\ttoken,\n\t}\n\tstore.logger.info(\n\t\t`⭕`,\n\t\ttoken.type,\n\t\ttoken.key,\n\t\t`operation start in store \"${store.config.name}\"${\n\t\t\t!isChildStore(store)\n\t\t\t\t? ``\n\t\t\t\t: ` ${store.transactionMeta.phase} \"${store.transactionMeta.update.key}\"`\n\t\t}`,\n\t)\n}\nexport const closeOperation = (store: Store): void => {\n\tif (store.operation.open) {\n\t\tstore.logger.info(\n\t\t\t`🔴`,\n\t\t\tstore.operation.token.type,\n\t\t\tstore.operation.token.key,\n\t\t\t`operation done in store \"${store.config.name}\"`,\n\t\t)\n\t}\n\tstore.operation = { open: false }\n\tstore.on.operationClose.next(store.operation)\n}\n\nexport const isDone = (store: Store, key: string): boolean => {\n\tif (!store.operation.open) {\n\t\tstore.logger.error(\n\t\t\t`🐞`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`isDone called outside of an operation. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn true\n\t}\n\treturn store.operation.done.has(key)\n}\nexport const markDone = (store: Store, key: string): void => {\n\tif (!store.operation.open) {\n\t\tstore.logger.error(\n\t\t\t`🐞`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`markDone called outside of an operation. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.operation.done.add(key)\n}\n","import type { Atom, Selector } from \"..\"\nimport { evictCachedValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Store } from \"../store\"\n\nexport function evictDownStream(store: Store, atom: Atom<any>): void {\n\tconst target = newest(store)\n\tconst downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key)\n\ttarget.logger.info(\n\t\t`🧹`,\n\t\tatom.type,\n\t\tatom.key,\n\t\tdownstreamKeys\n\t\t\t? `evicting ${downstreamKeys.size} states downstream:`\n\t\t\t: `no downstream states`,\n\t\tdownstreamKeys ?? `to evict`,\n\t)\n\tif (downstreamKeys) {\n\t\tif (target.operation.open) {\n\t\t\ttarget.logger.info(\n\t\t\t\t`🧹`,\n\t\t\t\tatom.type,\n\t\t\t\tatom.key,\n\t\t\t\t`[ ${[...target.operation.done].join(`, `)} ] already done`,\n\t\t\t)\n\t\t}\n\t\tfor (const key of downstreamKeys) {\n\t\t\tif (isDone(target, key)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tevictCachedValue(target, key)\n\t\t\tmarkDone(target, key)\n\t\t}\n\t}\n}\n\nexport function evictDownStreamFromSelector(\n\tstore: Store,\n\tselector: Selector<any>,\n): void {\n\tconst target = newest(store)\n\tconst relationEntries = target.selectorGraph\n\t\t.getRelationEntries({\n\t\t\tupstreamSelectorKey: selector.key,\n\t\t})\n\t\t.filter(([_, { source }]) => source === selector.key)\n\tfor (const [downstreamSelectorKey] of relationEntries) {\n\t\tif (isDone(target, downstreamSelectorKey)) {\n\t\t\tcontinue\n\t\t}\n\t\tevictCachedValue(target, downstreamSelectorKey)\n\t\tmarkDone(target, downstreamSelectorKey)\n\t}\n}\n","import type { StateUpdate } from \"atom.io\"\n\nimport type { ReadableState } from \".\"\nimport { closeOperation, isChildStore, openOperation } from \".\"\nimport { Future } from \"./future\"\nimport { copyMutableIfNeeded } from \"./set-state/copy-mutable-if-needed\"\nimport {\n\tevictDownStream,\n\tevictDownStreamFromSelector,\n} from \"./set-state/evict-downstream\"\nimport type { Store } from \"./store\"\nimport type { Subject } from \"./subject\"\n\nexport function cacheValue<T>(\n\tstore: Store,\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n): T\nexport function cacheValue<T extends Promise<any>>(\n\tstore: Store,\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n): Future<T>\nexport function cacheValue<T>(\n\ttarget: Store,\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n): Future<T> | T {\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future && !currentValue.done) {\n\t\tconst future = currentValue\n\t\tif (value instanceof Promise) {\n\t\t\tfuture.use(value)\n\t\t\treturn future\n\t\t}\n\t\ttarget.valueMap.set(key, value)\n\t\treturn value\n\t}\n\tif (value instanceof Promise) {\n\t\tconst future = new Future<T>(value)\n\t\ttarget.valueMap.set(key, future)\n\t\tfuture\n\t\t\t.then(function handleResolvedFuture(resolved) {\n\t\t\t\tconst current = target.valueMap.get(key)\n\t\t\t\tif (current === future) {\n\t\t\t\t\tcacheValue(target, key, resolved, subject)\n\t\t\t\t\tconst atom = target.atoms.get(key)\n\t\t\t\t\tif (atom) {\n\t\t\t\t\t\topenOperation(target, atom)\n\t\t\t\t\t\tevictDownStream(target, atom)\n\t\t\t\t\t\tcloseOperation(target)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst selector =\n\t\t\t\t\t\t\ttarget.writableSelectors.get(key) ??\n\t\t\t\t\t\t\ttarget.readonlySelectors.get(key)\n\t\t\t\t\t\tif (selector) {\n\t\t\t\t\t\t\topenOperation(target, selector)\n\t\t\t\t\t\t\tevictDownStreamFromSelector(target, selector)\n\t\t\t\t\t\t\tcloseOperation(target)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsubject.next({ newValue: resolved, oldValue: future })\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch((thrown) => {\n\t\t\t\ttarget.logger.error(`💥`, `state`, key, `rejected:`, thrown)\n\t\t\t})\n\t\treturn future\n\t}\n\ttarget.valueMap.set(key, value)\n\treturn value\n}\n\nexport const readCachedValue = <T>(\n\tstate: ReadableState<any>,\n\ttarget: Store,\n): T => {\n\ttarget.logger.info(`📖`, state.type, state.key, `reading cached value`)\n\tlet value = target.valueMap.get(state.key) as T\n\tif (state.type === `mutable_atom` && isChildStore(target)) {\n\t\tconst { parent } = target\n\t\tconst copiedValue = copyMutableIfNeeded(target, state, parent)\n\t\tvalue = copiedValue\n\t}\n\treturn value\n}\n\nexport const evictCachedValue = (target: Store, key: string): void => {\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future) {\n\t\tconst selector =\n\t\t\ttarget.writableSelectors.get(key) ?? target.readonlySelectors.get(key)\n\t\tif (selector) {\n\t\t\tselector.get()\n\t\t}\n\t\treturn\n\t}\n\tif (target.operation.open) {\n\t\ttarget.operation.prev.set(key, currentValue)\n\t}\n\ttarget.valueMap.delete(key)\n\ttarget.logger.info(`🗑`, `state`, key, `evicted`)\n}\n","import type { ReadableState } from \"..\"\nimport { cacheValue, readCachedValue } from \"../caching\"\nimport type { Store } from \"../store\"\n\nexport const readOrComputeValue = <T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n): T => {\n\tif (target.valueMap.has(state.key)) {\n\t\treturn readCachedValue(state, target)\n\t}\n\tswitch (state.type) {\n\t\tcase `readonly_held_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\tcase `writable_pure_selector`:\n\t\t\ttarget.logger.info(`🧮`, state.type, state.key, `computing value`)\n\t\t\treturn state.get()\n\t\tcase `atom`:\n\t\tcase `mutable_atom`: {\n\t\t\tconst def = state.default\n\t\t\tlet defaultValue: T\n\t\t\tif (def instanceof Function) {\n\t\t\t\tdefaultValue = def()\n\t\t\t} else {\n\t\t\t\tdefaultValue = def\n\t\t\t}\n\t\t\tconst cachedValue = cacheValue(\n\t\t\t\ttarget,\n\t\t\t\tstate.key,\n\t\t\t\tdefaultValue,\n\t\t\t\tstate.subject,\n\t\t\t)\n\t\t\ttarget.logger.info(\n\t\t\t\t`💁`,\n\t\t\t\t`atom`,\n\t\t\t\tstate.key,\n\t\t\t\t`could not find cached value; using default`,\n\t\t\t\tdefaultValue,\n\t\t\t)\n\t\t\treturn cachedValue\n\t\t}\n\t}\n}\n","import type { Atom, Selector } from \"..\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport type { Store } from \"../store\"\nimport { recallState } from \"./recall-state\"\n\nexport const subscribeToRootDependency = (\n\ttarget: Store,\n\tselector: Selector<any>,\n\tatom: Atom<any>,\n): (() => void) => {\n\treturn atom.subject.subscribe(\n\t\t`${selector.type}:${selector.key}`,\n\t\t(atomChange) => {\n\t\t\ttarget.logger.info(\n\t\t\t\t`📢`,\n\t\t\t\tselector.type,\n\t\t\t\tselector.key,\n\t\t\t\t`root`,\n\t\t\t\tatom.key,\n\t\t\t\t`went`,\n\t\t\t\tatomChange.oldValue,\n\t\t\t\t`->`,\n\t\t\t\tatomChange.newValue,\n\t\t\t)\n\t\t\tconst oldValue = recallState(target, selector)\n\t\t\tconst newValue = readOrComputeValue(target, selector)\n\t\t\ttarget.logger.info(\n\t\t\t\t`✨`,\n\t\t\t\tselector.type,\n\t\t\t\tselector.key,\n\t\t\t\t`went`,\n\t\t\t\toldValue,\n\t\t\t\t`->`,\n\t\t\t\tnewValue,\n\t\t\t)\n\t\t\tselector.subject.next({ newValue, oldValue })\n\t\t},\n\t)\n}\n\n// export const subscribeToRootAtoms = (\n// \tstore: Store,\n// \tselector: Selector<any>,\n// ): (() => void)[] => {\n// \tconst target = newest(store)\n// \tconst dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(\n// \t\t(atom) => subscribeToRootDependency(target, selector, atom),\n// \t)\n// \treturn dependencySubscriptions\n// }\n","import type {\n\tFamilyMetadata,\n\tRegularAtomFamilyOptions,\n\tRegularAtomFamilyToken,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { prettyPrintTokenType, type RegularAtomFamily } from \"..\"\nimport { createRegularAtom } from \"../atom\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createRegularAtomFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: RegularAtomFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): RegularAtomFamilyToken<T, K> {\n\tconst familyToken = {\n\t\tkey: options.key,\n\t\ttype: `atom_family`,\n\t} as const satisfies RegularAtomFamilyToken<T, K>\n\n\tconst existing = store.families.get(options.key)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\t`atom_family`,\n\t\t\toptions.key,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\n\tconst subject = new Subject<\n\t\tStateCreation<RegularAtomToken<T>> | StateDisposal<RegularAtomToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): RegularAtomToken<any> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\tconst fullKey = `${options.key}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst def = options.default\n\t\tconst individualOptions: RegularAtomOptions<T> = {\n\t\t\tkey: fullKey,\n\t\t\tdefault: def instanceof Function ? () => def(key) : def,\n\t\t}\n\t\tif (options.effects) {\n\t\t\tindividualOptions.effects = options.effects(key)\n\t\t}\n\n\t\tconst token = createRegularAtom(target, individualOptions, family)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst atomFamily = Object.assign(familyFunction, familyToken, {\n\t\tsubject,\n\t\tinstall: (s: Store) => createRegularAtomFamily(s, options),\n\t\tinternalRoles,\n\t}) satisfies RegularAtomFamily<T, K>\n\n\tstore.families.set(options.key, atomFamily)\n\tstore.defaults.set(options.key, options.default)\n\treturn familyToken\n}\n","import type {\n\tAtomFamilyToken,\n\tMutableAtomFamilyOptions,\n\tMutableAtomFamilyToken,\n\tRegularAtomFamilyOptions,\n\tRegularAtomFamilyToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport { createMutableAtomFamily, type Transceiver } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { createRegularAtomFamily } from \"./create-regular-atom-family\"\n\nexport function createAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\toptions: MutableAtomFamilyOptions<T, J, K>,\n): MutableAtomFamilyToken<T, J, K>\nexport function createAtomFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: RegularAtomFamilyOptions<T, K>,\n): RegularAtomFamilyToken<T, K>\nexport function createAtomFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions:\n\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t| RegularAtomFamilyOptions<T, K>,\n): AtomFamilyToken<any, any> {\n\tconst isMutable = `mutable` in options\n\n\tif (isMutable) {\n\t\treturn createMutableAtomFamily(store, options)\n\t}\n\treturn createRegularAtomFamily<T, K>(store, options)\n}\n","export type Modify<T> = (thing: T) => T\n\nexport const become =\n\t<T>(nextVersionOfThing: Modify<T> | T) =>\n\t(originalThing: T): T =>\n\t\tnextVersionOfThing instanceof Function\n\t\t\t? nextVersionOfThing(originalThing)\n\t\t\t: nextVersionOfThing\n","import type { StateUpdate } from \"atom.io\"\n\nimport type { Atom, Selector, Store } from \"..\"\n\nexport const emitUpdate = <T>(\n\tstore: Store,\n\tstate: Atom<T> | Selector<T>,\n\tupdate: StateUpdate<T>,\n): void => {\n\tswitch (state.type) {\n\t\tcase `mutable_atom`:\n\t\t\tstore.logger.info(\n\t\t\t\t`📢`,\n\t\t\t\tstate.type,\n\t\t\t\tstate.key,\n\t\t\t\t`is now (`,\n\t\t\t\tupdate.newValue,\n\t\t\t\t`) subscribers:`,\n\t\t\t\tstate.subject.subscribers,\n\t\t\t)\n\t\t\tbreak\n\t\tcase `atom`:\n\t\tcase `writable_pure_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\tcase `readonly_held_selector`:\n\t\t\tstore.logger.info(\n\t\t\t\t`📢`,\n\t\t\t\tstate.type,\n\t\t\t\tstate.key,\n\t\t\t\t`went (`,\n\t\t\t\tupdate.oldValue,\n\t\t\t\t`->`,\n\t\t\t\tupdate.newValue,\n\t\t\t\t`) subscribers:`,\n\t\t\t\tstate.subject.subscribers,\n\t\t\t)\n\t}\n\tstate.subject.next(update)\n}\n","import type { KeyedStateUpdate } from \"atom.io\"\n\nimport type { Atom, Store } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport { isTransceiver, type Transceiver } from \"../mutable\"\nimport { markDone } from \"../operation\"\nimport { isChildStore } from \"../transaction/is-root-store\"\nimport { become } from \"./become\"\nimport { copyMutableIfNeeded } from \"./copy-mutable-if-needed\"\nimport { emitUpdate } from \"./emit-update\"\nimport { evictDownStream } from \"./evict-downstream\"\n\nexport const setAtom = <T>(\n\ttarget: Store,\n\tatom: Atom<T>,\n\tnext: T | ((oldValue: T) => T),\n): void => {\n\tconst oldValue = readOrComputeValue(target, atom)\n\tlet newValue = oldValue\n\tif (atom.type === `mutable_atom` && isChildStore(target)) {\n\t\tconst { parent } = target\n\t\tconst copiedValue = copyMutableIfNeeded(target, atom, parent)\n\t\tnewValue = copiedValue\n\t}\n\tnewValue = become(next)(newValue)\n\ttarget.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)\n\tnewValue = cacheValue(target, atom.key, newValue, atom.subject)\n\tmarkDone(target, atom.key)\n\tevictDownStream(target, atom)\n\tconst update = { oldValue, newValue }\n\tif (!isChildStore(target)) {\n\t\temitUpdate(target, atom, update)\n\t\treturn\n\t}\n\tif (target.on.transactionApplying.state === null) {\n\t\tconst { key } = atom\n\t\tif (isTransceiver(update.newValue)) {\n\t\t\treturn\n\t\t}\n\t\tconst atomUpdate: KeyedStateUpdate<T> = {\n\t\t\ttype: `atom_update`,\n\t\t\tkey,\n\t\t\t...update,\n\t\t}\n\t\tif (atom.family) {\n\t\t\tatomUpdate.family = atom.family\n\t\t}\n\t\ttarget.transactionMeta.update.updates.push(atomUpdate)\n\t\ttarget.logger.info(\n\t\t\t`📁`,\n\t\t\t`atom`,\n\t\t\tkey,\n\t\t\t`stowed (`,\n\t\t\tupdate.oldValue,\n\t\t\t`->`,\n\t\t\tupdate.newValue,\n\t\t\t`)`,\n\t\t)\n\t} else if (atom.key.startsWith(`*`)) {\n\t\tconst mutableKey = atom.key.slice(1)\n\t\tconst mutableAtom = target.atoms.get(mutableKey) as Atom<any>\n\t\tlet transceiver: Transceiver<any> = target.valueMap.get(mutableKey)\n\t\tif (mutableAtom.type === `mutable_atom` && isChildStore(target)) {\n\t\t\tconst { parent } = target\n\t\t\tconst copiedValue = copyMutableIfNeeded(target, mutableAtom, parent)\n\t\t\ttransceiver = copiedValue\n\t\t}\n\t\tconst accepted = transceiver.do(update.newValue) === null\n\t\tif (accepted) evictDownStream(target, mutableAtom)\n\t}\n}\n","import type { Atom, WritableState } from \"..\"\nimport { traceRootSelectorAtoms } from \"..\"\nimport type { Store } from \"../store\"\nimport { setAtom } from \"./set-atom\"\n\nfunction resetAtom(store: Store, state: Atom<any>) {\n\tlet def = state.default\n\tif (def instanceof Function) {\n\t\tdef = def()\n\t}\n\tsetAtom(store, state, def)\n}\n\nexport function resetAtomOrSelector(\n\tstore: Store,\n\tstate: WritableState<any>,\n): void {\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tresetAtom(store, state)\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\t{\n\t\t\t\tconst atoms = traceRootSelectorAtoms(store, state.key)\n\t\t\t\tfor (const atom of atoms.values()) {\n\t\t\t\t\tresetAtom(store, atom)\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t}\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport type { Store } from \"../store\"\n\nexport function getFamilyOfToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\ttoken: MutableAtomToken<T, J, K>,\n): MutableAtomFamilyToken<T, J, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, K>,\n): RegularAtomFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, K>,\n): WritablePureSelectorFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, K>,\n): ReadonlyPureSelectorFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableToken<T, K>,\n): WritableFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K>,\n): ReadableFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken(\n\tstore: Store,\n\ttoken: ReadableToken<any, any>,\n): ReadableFamilyToken<any, any> | undefined {\n\tif (token.family) {\n\t\tconst family = store.families.get(token.family.key)\n\t\tif (family) {\n\t\t\treturn family\n\t\t}\n\t}\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { type Canonical, parseJson } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { closeOperation, openOperation } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { resetAtomOrSelector } from \"./reset-atom-or-selector\"\n\nexport function resetInStore(store: Store, token: WritableToken<any>): void\n\nexport function resetInStore<K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<any, K>,\n\tkey: K,\n): void\n\nexport function resetInStore<T>(\n\tstore: Store,\n\t...params:\n\t\t| [token: WritableFamilyToken<T, Canonical>, key: Canonical]\n\t\t| [token: WritableToken<T>]\n): void {\n\tlet token: WritableToken<T>\n\tlet family: WritableFamilyToken<T, Canonical> | null\n\tlet key: Canonical | null\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t\tfamily = getFamilyOfToken(store, token) ?? null\n\t\tif (family) {\n\t\t\tkey = token.family ? parseJson(token.family.subKey) : null\n\t\t\ttoken = findInStore(store, family, key)\n\t\t}\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\ttoken = findInStore(store, family, key)\n\t}\n\n\tif (`counterfeit` in token && `family` in token) {\n\t\tconst subKey = token.family.subKey\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === subKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`could not be reset because it was not found in the store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `This state was previously disposed:\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace was found.`,\n\t\t)\n\t\treturn\n\t}\n\n\tconst rejectionTime = openOperation(store, token)\n\tif (rejectionTime) {\n\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t`waiting to reset \"${token.key}\" at T-${rejectionTime}`,\n\t\t\t() => {\n\t\t\t\tunsubscribe()\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🟢`,\n\t\t\t\t\ttoken.type,\n\t\t\t\t\ttoken.key,\n\t\t\t\t\t`resuming deferred resetState from T-${rejectionTime}`,\n\t\t\t\t)\n\t\t\t\tresetInStore(store, token)\n\t\t\t},\n\t\t)\n\t\treturn\n\t}\n\tconst state = withdraw(store, token)\n\tresetAtomOrSelector(store, state)\n\tcloseOperation(store)\n}\n","import type { WritableState } from \"..\"\nimport type { Store } from \"../store\"\nimport { setAtom } from \"./set-atom\"\n\nexport const setAtomOrSelector = <T>(\n\tstore: Store,\n\tstate: WritableState<T>,\n\tvalue: T | ((oldValue: T) => T),\n): void => {\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tsetAtom(store, state, value)\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\tstate.set(value)\n\t\t\tbreak\n\t}\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { type Canonical, parseJson } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { closeOperation, openOperation } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { setAtomOrSelector } from \"./set-atom-or-selector\"\n\nexport function setIntoStore<T, New extends T>(\n\tstore: Store,\n\ttoken: WritableToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n): void\n\nexport function setIntoStore<T, K extends Canonical, New extends T>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: K,\n\tvalue: New | ((oldValue: T) => New),\n): void\n\nexport function setIntoStore<T, New extends T>(\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, Canonical>,\n\t\t\t\tkey: Canonical,\n\t\t\t\tvalue: New | ((oldValue: T) => New),\n\t\t ]\n\t\t| [token: WritableToken<T>, value: New | ((oldValue: T) => New)]\n): void {\n\tlet token: WritableToken<T>\n\tlet family: WritableFamilyToken<T, Canonical> | null\n\tlet key: Canonical | null\n\tlet value: New | ((oldValue: T) => New)\n\tif (params.length === 2) {\n\t\ttoken = params[0]\n\t\tvalue = params[1]\n\t\tfamily = getFamilyOfToken(store, token) ?? null\n\t\tif (family) {\n\t\t\tkey = token.family ? parseJson(token.family.subKey) : null\n\t\t\ttoken = findInStore(store, family, key)\n\t\t}\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\tvalue = params[2]\n\t\ttoken = findInStore(store, family, key)\n\t}\n\n\tif (`counterfeit` in token && `family` in token) {\n\t\tconst subKey = token.family.subKey\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === subKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`could not be set because it was not found in the store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `This state was previously disposed:\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace was found.`,\n\t\t)\n\t\treturn\n\t}\n\n\tconst rejectionTime = openOperation(store, token)\n\tif (rejectionTime) {\n\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t`waiting to set \"${token.key}\" at T-${rejectionTime}`,\n\t\t\t() => {\n\t\t\t\tunsubscribe()\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🟢`,\n\t\t\t\t\ttoken.type,\n\t\t\t\t\ttoken.key,\n\t\t\t\t\t`resuming deferred setState from T-${rejectionTime}`,\n\t\t\t\t)\n\t\t\t\tsetIntoStore(store, token, value)\n\t\t\t},\n\t\t)\n\t\treturn\n\t}\n\tconst state = withdraw(store, token)\n\tsetAtomOrSelector(store, state, value)\n\tcloseOperation(store)\n}\n","import { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\n\nexport type AtomKey<T> = string & { __atomKey?: never; __brand?: T }\nexport type SelectorKey<T> = string & { __selectorKey?: never; __brand?: T }\nexport type ReadonlySelectorKey<T> = string & {\n\t__readonlySelectorKey?: never\n\t__brand?: T\n}\n\nexport const isAtomKey = (store: Store, key: string): key is AtomKey<unknown> =>\n\tnewest(store).atoms.has(key)\nexport const isSelectorKey = (\n\tstore: Store,\n\tkey: string,\n): key is SelectorKey<unknown> => newest(store).writableSelectors.has(key)\nexport const isReadonlySelectorKey = (\n\tstore: Store,\n\tkey: string,\n): key is ReadonlySelectorKey<unknown> =>\n\tnewest(store).readonlySelectors.has(key)\n\nexport type StateKey<T> = AtomKey<T> | ReadonlySelectorKey<T> | SelectorKey<T>\nexport const isStateKey = (\n\tstore: Store,\n\tkey: string,\n): key is StateKey<unknown> =>\n\tisAtomKey(store, key) ||\n\tisSelectorKey(store, key) ||\n\tisReadonlySelectorKey(store, key)\n","import type { AtomKey, ReadonlySelectorKey, SelectorKey } from \"../keys\"\nimport { isStateKey } from \"../keys\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const getSelectorDependencyKeys = (\n\tstore: Store,\n\tkey: string,\n): (\n\t| AtomKey<unknown>\n\t| ReadonlySelectorKey<unknown>\n\t| SelectorKey<unknown>\n)[] => {\n\tconst sources = newest(store)\n\t\t.selectorGraph.getRelationEntries({ downstreamSelectorKey: key })\n\t\t.filter(([_, { source }]) => source !== key)\n\t\t.map(([_, { source }]) => source)\n\t\t.filter((source) => isStateKey(store, source))\n\treturn sources\n}\n","import type { Atom, Store } from \"..\"\nimport { isAtomKey } from \"../keys\"\nimport { getSelectorDependencyKeys } from \"./get-selector-dependency-keys\"\n\nexport const traceRootSelectorAtoms = (\n\tstore: Store,\n\tselectorKey: string,\n\tcovered: Set<string> = new Set<string>(),\n): Map<string, Atom<unknown>> => {\n\tconst dependencies = getSelectorDependencyKeys(store, selectorKey)\n\n\tconst roots = new Map<string, Atom<unknown>>()\n\n\twhile (dependencies.length > 0) {\n\t\t// biome-ignore lint/style/noNonNullAssertion: just checked length ^^^\n\t\tconst dependencyKey = dependencies.pop()!\n\t\tif (covered.has(dependencyKey)) {\n\t\t\tcontinue\n\t\t}\n\t\tcovered.add(dependencyKey)\n\t\tif (isAtomKey(store, dependencyKey)) {\n\t\t\tconst atom = store.atoms.get(dependencyKey) as Atom<unknown>\n\t\t\troots.set(atom.key, atom)\n\t\t} else {\n\t\t\tdependencies.push(...getSelectorDependencyKeys(store, dependencyKey))\n\t\t}\n\t}\n\treturn roots\n}\n","import type { ReadonlyPureSelectorToken, WritableToken } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { traceRootSelectorAtoms } from \"./trace-selector-atoms\"\n\nexport const updateSelectorAtoms = (\n\tstore: Store,\n\tselectorType:\n\t\t| `readonly_held_selector`\n\t\t| `readonly_pure_selector`\n\t\t| `writable_held_selector`\n\t\t| `writable_pure_selector`,\n\tselectorKey: string,\n\tdependency: ReadonlyPureSelectorToken<unknown> | WritableToken<unknown>,\n\tcovered: Set<string>,\n): void => {\n\tconst target = newest(store)\n\tconst { type: dependencyType, key: dependencyKey } = dependency\n\tif (dependencyType === `atom` || dependencyType === `mutable_atom`) {\n\t\ttarget.selectorAtoms.set({\n\t\t\tselectorKey,\n\t\t\tatomKey: dependencyKey,\n\t\t})\n\t\tstore.logger.info(\n\t\t\t`🔍`,\n\t\t\tselectorType,\n\t\t\tselectorKey,\n\t\t\t`discovers root atom \"${dependencyKey}\"`,\n\t\t)\n\t} else {\n\t\tconst rootKeys = traceRootSelectorAtoms(store, dependencyKey, covered)\n\t\tstore.logger.info(\n\t\t\t`🔍`,\n\t\t\tselectorType,\n\t\t\tselectorKey,\n\t\t\t`discovers root atoms: [ ${[...rootKeys.values()]\n\t\t\t\t.map((root) => `\"${root.key}\"`)\n\t\t\t\t.join(`, `)} ]`,\n\t\t)\n\t\tfor (const { key: atomKey } of rootKeys.values()) {\n\t\t\ttarget.selectorAtoms = target.selectorAtoms.set({\n\t\t\t\tselectorKey,\n\t\t\t\tatomKey,\n\t\t\t})\n\t\t}\n\t}\n\tcovered.add(dependencyKey)\n}\n","import type {\n\tfindState,\n\tReadableFamilyToken,\n\tReadableToken,\n\tsetState,\n\tSetterToolkit,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { setAtomOrSelector } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { updateSelectorAtoms } from \"./update-selector-atoms\"\n\nexport const registerSelector = (\n\tstore: Store,\n\tselectorType:\n\t\t| `readonly_held_selector`\n\t\t| `readonly_pure_selector`\n\t\t| `writable_held_selector`\n\t\t| `writable_pure_selector`,\n\tselectorKey: string,\n\tcovered: Set<string>,\n): SetterToolkit => ({\n\tget: (\n\t\t...params:\n\t\t\t| [ReadableFamilyToken<any, any>, Json.Serializable]\n\t\t\t| [ReadableToken<any>]\n\t) => {\n\t\tconst target = newest(store)\n\t\tlet dependency: ReadableToken<any>\n\n\t\tif (params.length === 2) {\n\t\t\tconst [family, key] = params\n\t\t\tdependency = findInStore(store, family, key)\n\t\t} else {\n\t\t\t;[dependency] = params\n\t\t}\n\n\t\tconst dependencyState = withdraw(store, dependency)\n\t\tconst dependencyValue = readOrComputeValue(store, dependencyState)\n\t\tconst dependencyKey = dependency.key\n\n\t\tstore.logger.info(\n\t\t\t`🔌`,\n\t\t\tselectorType,\n\t\t\tselectorKey,\n\t\t\t`registers dependency ( \"${dependencyKey}\" =`,\n\t\t\tdependencyValue,\n\t\t\t`)`,\n\t\t)\n\n\t\ttarget.selectorGraph.set(\n\t\t\t{\n\t\t\t\tupstreamSelectorKey: dependencyKey,\n\t\t\t\tdownstreamSelectorKey: selectorKey,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: dependency.key,\n\t\t\t},\n\t\t)\n\t\tupdateSelectorAtoms(\n\t\t\tstore,\n\t\t\tselectorType,\n\t\t\tselectorKey,\n\t\t\tdependency as any,\n\t\t\tcovered,\n\t\t)\n\t\treturn dependencyValue\n\t},\n\tset: (<T, New extends T>(\n\t\t...params:\n\t\t\t| [\n\t\t\t\t\ttoken: WritableFamilyToken<T, any>,\n\t\t\t\t\tkey: Json.Serializable,\n\t\t\t\t\tvalue: New | ((oldValue: any) => New),\n\t\t\t ]\n\t\t\t| [token: WritableToken<T>, value: New | ((oldValue: T) => New)]\n\t) => {\n\t\tlet token: WritableToken<T>\n\t\tlet value: New | ((oldValue: T) => New)\n\t\tif (params.length === 2) {\n\t\t\ttoken = params[0]\n\t\t\tvalue = params[1]\n\t\t} else {\n\t\t\tconst family = params[0]\n\t\t\tconst key = params[1]\n\t\t\tvalue = params[2]\n\t\t\ttoken = findInStore(store, family, key)\n\t\t}\n\t\tconst target = newest(store)\n\t\tconst state = withdraw(target, token)\n\t\tsetAtomOrSelector(target, state, value)\n\t}) as typeof setState,\n\tfind: ((...args: Parameters<typeof findState>) =>\n\t\tfindInStore(store, ...args)) as typeof findState,\n\tjson: (token) => getJsonToken(store, token),\n})\n","import type {\n\tFamilyMetadata,\n\tReadonlyHeldSelectorOptions,\n\tReadonlyHeldSelectorToken,\n} from \"atom.io\"\n\nimport type { ReadonlyHeldSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadonlyHeldSelector = <T extends object>(\n\tstore: Store,\n\toptions: ReadonlyHeldSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): ReadonlyHeldSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst covered = new Set<string>()\n\tconst { key, const: constant } = options\n\tconst type = `readonly_held_selector` as const\n\tconst { get, find, json } = registerSelector(target, type, key, covered)\n\tconst getSelf = () => {\n\t\tconst innerTarget = newest(store)\n\t\tconst upstreamStates = innerTarget.selectorGraph.getRelationEntries({\n\t\t\tdownstreamSelectorKey: key,\n\t\t})\n\t\tfor (const [downstreamSelectorKey, { source }] of upstreamStates) {\n\t\t\tif (source !== key) {\n\t\t\t\tinnerTarget.selectorGraph.delete(downstreamSelectorKey, key)\n\t\t\t}\n\t\t}\n\t\tinnerTarget.selectorAtoms.delete(key)\n\t\toptions.get({ get, find, json }, constant)\n\t\tcacheValue(newest(store), key, constant, subject)\n\t\tcovered.clear()\n\t\treturn constant\n\t}\n\n\tconst readonlySelector: ReadonlyHeldSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlyHeldSelector(s, options, family),\n\t\tget: getSelf,\n\t\t...(family && { family }),\n\t}\n\ttarget.readonlySelectors.set(key, readonlySelector)\n\tstore.logger.info(`✨`, type, key, `=`, constant)\n\tconst token: ReadonlyHeldSelectorToken<T> = {\n\t\tkey,\n\t\ttype,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyPureSelectorOptions,\n\tReadonlyPureSelectorToken,\n} from \"atom.io\"\n\nimport type { ReadonlyPureSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadonlyPureSelector = <T>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): ReadonlyPureSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst covered = new Set<string>()\n\tconst key = options.key\n\tconst type = `readonly_pure_selector` as const\n\tconst { get, find, json } = registerSelector(target, type, key, covered)\n\tconst getSelf = () => {\n\t\tconst innerTarget = newest(store)\n\t\tconst upstreamStates = innerTarget.selectorGraph.getRelationEntries({\n\t\t\tdownstreamSelectorKey: key,\n\t\t})\n\t\tfor (const [downstreamSelectorKey, { source }] of upstreamStates) {\n\t\t\tif (source !== key) {\n\t\t\t\tinnerTarget.selectorGraph.delete(downstreamSelectorKey, key)\n\t\t\t}\n\t\t}\n\t\tinnerTarget.selectorAtoms.delete(key)\n\t\tconst value = options.get({ get, find, json })\n\t\tconst cached = cacheValue(innerTarget, key, value, subject)\n\t\tstore.logger.info(`✨`, type, key, `=`, cached)\n\t\tcovered.clear()\n\t\treturn cached\n\t}\n\n\tconst readonlySelector: ReadonlyPureSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlyPureSelector(s, options, family),\n\t\tget: getSelf,\n\t\t...(family && { family }),\n\t}\n\ttarget.readonlySelectors.set(key, readonlySelector)\n\tconst token: ReadonlyPureSelectorToken<T> = {\n\t\tkey,\n\t\ttype,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\treturn token\n}\n","import { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { isChildStore } from \"./is-root-store\"\n\nexport const abortTransaction = (store: Store): void => {\n\tconst target = newest(store)\n\tif (!isChildStore(target)) {\n\t\tstore.logger.warn(\n\t\t\t`🐞`,\n\t\t\t`transaction`,\n\t\t\t`???`,\n\t\t\t`abortTransaction called outside of a transaction. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.logger.info(\n\t\t`🪂`,\n\t\t`transaction`,\n\t\ttarget.transactionMeta.update.key,\n\t\t`Aborting transaction`,\n\t)\n\ttarget.parent.child = null\n}\n","export function capitalize<S extends string>(string: S): Capitalize<S> {\n\treturn (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>\n}\n","import type { AtomIOToken } from \"atom.io\"\n\nimport { capitalize } from \"./capitalize\"\n\nexport function prettyPrintTokenType(token: AtomIOToken): string {\n\treturn token.type.split(`_`).map(capitalize).join(` `)\n}\n","import type { AtomIOToken } from \"atom.io\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { prettyPrintTokenType } from \"./pretty-print\"\nimport type { Store } from \"./store\"\n\nexport class NotFoundError extends Error {\n\tpublic constructor(token: AtomIOToken, store: Store) {\n\t\tsuper(\n\t\t\t`${prettyPrintTokenType(token)} ${stringifyJson(token.key)} not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import type { TransactionToken } from \"atom.io\"\n\nimport { NotFoundError } from \"../not-found-error\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Func } from \"../utility-types\"\n\nexport function actUponStore<F extends Func>(\n\tstore: Store,\n\ttoken: TransactionToken<F>,\n\tid: string,\n): (...parameters: Parameters<F>) => ReturnType<F> {\n\treturn (...parameters: Parameters<F>): ReturnType<F> => {\n\t\tconst tx = withdraw(store, token)\n\t\tif (tx) {\n\t\t\treturn tx.run(parameters, id)\n\t\t}\n\t\tthrow new NotFoundError(token, store)\n\t}\n}\n","import type { KeyedStateUpdate, RegularAtomToken } from \"atom.io\"\n\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\n\nexport function ingestAtomUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tatomUpdate: KeyedStateUpdate<any>,\n\tstore: Store,\n): void {\n\tconst { key, newValue, oldValue } = atomUpdate\n\tconst value = applying === `newValue` ? newValue : oldValue\n\tconst token: RegularAtomToken<unknown> = { key, type: `atom` }\n\tif (atomUpdate.family) {\n\t\tObject.assign(token, { family: atomUpdate.family })\n\t}\n\tsetIntoStore(store, token, value)\n}\n","export function getTrace(error: Error): string {\n\tconst { stack } = error\n\tif (stack) {\n\t\treturn `\\n` + stack.split(`\\n`)?.slice(1)?.join(`\\n`)\n\t}\n\treturn ``\n}\n","import type {\n\tAbove,\n\tClaim,\n\tCompoundFrom,\n\tCompoundTypedKey,\n\tHierarchy,\n\tMoleculeCreation,\n\tMoleculeDisposal,\n\tMoleculeTransfer,\n\tSingularTypedKey,\n\tVassal,\n} from \"atom.io\"\nimport type { Canonical, stringified } from \"atom.io/json\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\n\nimport { disposeFromStore, findInStore } from \"./families\"\nimport { getTrace } from \"./get-trace\"\nimport { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\nimport { IMPLICIT } from \"./store\"\nimport { isChildStore } from \"./transaction\"\n\nexport type Molecule<K extends Canonical> = {\n\treadonly key: K\n\treadonly stringKey: stringified<K>\n\treadonly dependsOn: `all` | `any`\n}\n\nexport function makeRootMoleculeInStore<S extends string>(\n\tkey: S,\n\tstore: Store = IMPLICIT.STORE,\n): S {\n\tconst molecule = {\n\t\tkey,\n\t\tstringKey: stringifyJson(key),\n\t\tdependsOn: `any`,\n\t} satisfies Molecule<S>\n\tstore.molecules.set(stringifyJson(key), molecule)\n\treturn key\n}\n\nexport function allocateIntoStore<\n\tH extends Hierarchy,\n\tV extends Vassal<H>,\n\tA extends Above<V, H>,\n>(\n\tstore: Store,\n\tprovenance: A,\n\tkey: V,\n\tdependsOn: `all` | `any` = `any`,\n): Claim<V> {\n\tconst origin = provenance as Canonical | [Canonical, Canonical]\n\tconst stringKey = stringifyJson(key)\n\tconst invalidKeys: stringified<Canonical>[] = []\n\tconst target = newest(store)\n\n\tif (Array.isArray(origin)) {\n\t\tfor (const formerClaim of origin) {\n\t\t\tconst claimString = stringifyJson(formerClaim)\n\t\t\tconst claim = target.molecules.get(claimString)\n\t\t\tif (claim) {\n\t\t\t\tstore.moleculeGraph.set(claimString, stringKey, { source: claimString })\n\t\t\t} else {\n\t\t\t\tinvalidKeys.push(claimString)\n\t\t\t}\n\t\t}\n\t} else {\n\t\tconst claimString = stringifyJson(origin)\n\t\tconst claim = target.molecules.get(claimString)\n\t\tif (claim) {\n\t\t\tstore.moleculeGraph.set(claimString, stringKey, { source: claimString })\n\t\t} else {\n\t\t\tinvalidKeys.push(claimString)\n\t\t}\n\t}\n\tif (invalidKeys.length === 0) {\n\t\ttarget.molecules.set(stringKey, { key, stringKey, dependsOn })\n\t}\n\n\tconst creationEvent: MoleculeCreation = {\n\t\ttype: `molecule_creation`,\n\t\tkey,\n\t\tprovenance: origin,\n\t}\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.updates.push(creationEvent)\n\t} else {\n\t\ttarget.on.moleculeCreation.next(creationEvent)\n\t}\n\n\tfor (const claim of invalidKeys) {\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === claim,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`molecule`,\n\t\t\tkey,\n\t\t\t`allocation failed:`,\n\t\t\t`Could not allocate to ${claim} in store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `\\n ${claim} was most recently disposed\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace for ${claim} was found.`,\n\t\t)\n\t}\n\n\treturn key as Claim<V>\n}\n\nexport function fuseWithinStore<\n\tH extends Hierarchy,\n\tC extends CompoundFrom<H>,\n\tT extends C extends CompoundTypedKey<infer t, any, any> ? t : never,\n\tA extends C extends CompoundTypedKey<any, infer a, any> ? a : never,\n\tB extends C extends CompoundTypedKey<any, any, infer b> ? b : never,\n>(\n\tstore: Store,\n\ttype: T,\n\tsideA: SingularTypedKey<A>,\n\tsideB: SingularTypedKey<B>,\n): Claim<CompoundTypedKey<T, A, B>> {\n\tconst compoundKey: CompoundTypedKey<T, A, B> =\n\t\t`T$--${type}==${sideA}++${sideB}`\n\tconst above = [sideA, sideB] as Above<Vassal<H>, H>\n\tallocateIntoStore<H, Vassal<H>, Above<Vassal<H>, H>>(\n\t\tstore,\n\t\tabove,\n\t\tcompoundKey as Vassal<H>,\n\t\t`all`,\n\t)\n\treturn compoundKey\n}\n\nexport function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(\n\tstore: Store,\n\tclaim: Claim<V>,\n): void {\n\tconst stringKey = stringifyJson(claim)\n\n\tconst molecule = store.molecules.get(stringKey)\n\tif (!molecule) {\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === stringKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`molecule`,\n\t\t\tclaim,\n\t\t\t`deallocation failed:`,\n\t\t\t`Could not find allocation for ${stringKey} in store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `\\n This state was most recently deallocated\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace for ${stringKey} was found.`,\n\t\t)\n\t\treturn\n\t}\n\n\tconst joinKeys = store.moleculeJoins.getRelatedKeys(\n\t\tmolecule.key as string /* 💥 RECONCILE */,\n\t)\n\tif (joinKeys) {\n\t\tfor (const joinKey of joinKeys) {\n\t\t\tconst join = store.joins.get(joinKey)\n\t\t\tif (join) {\n\t\t\t\tjoin.relations.delete(molecule.key)\n\t\t\t\tjoin.molecules.delete(molecule.stringKey) // get rid of\n\t\t\t}\n\t\t}\n\t}\n\tstore.moleculeJoins.delete(molecule.stringKey)\n\n\tconst provenance: stringified<Canonical>[] = []\n\n\tconst values: [string, any][] = []\n\tconst disposalEvent: MoleculeDisposal = {\n\t\ttype: `molecule_disposal`,\n\t\tkey: molecule.key,\n\t\tvalues,\n\t\tprovenance,\n\t}\n\tconst target = newest(store)\n\ttarget.molecules.delete(stringKey)\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.updates.push(disposalEvent)\n\t}\n\tconst relatedMolecules = store.moleculeGraph.getRelationEntries({\n\t\tdownstreamMoleculeKey: molecule.stringKey,\n\t})\n\tif (relatedMolecules) {\n\t\tfor (const [relatedStringKey, { source }] of relatedMolecules) {\n\t\t\tif (source === molecule.stringKey) {\n\t\t\t\tconst relatedKey = parseJson(relatedStringKey)\n\t\t\t\tdeallocateFromStore<any, any>(store, relatedKey)\n\t\t\t} else {\n\t\t\t\tprovenance.push(source)\n\t\t\t}\n\t\t}\n\t}\n\tconst familyKeys = target.moleculeData.getRelatedKeys(molecule.stringKey)\n\tif (familyKeys) {\n\t\tfor (const familyKey of familyKeys) {\n\t\t\t// biome-ignore lint/style/noNonNullAssertion: tokens of molecules must have a family\n\t\t\tconst family = target.families.get(familyKey)!\n\t\t\tconst token = findInStore(store, family, molecule.key)\n\t\t\tvalues.push([family.key, token])\n\t\t\tdisposeFromStore(store, token)\n\t\t}\n\t}\n\n\ttarget.moleculeGraph.delete(molecule.stringKey)\n\ttarget.moleculeJoins.delete(molecule.stringKey)\n\ttarget.moleculeData.delete(molecule.stringKey)\n\n\tif (!isTransaction) {\n\t\ttarget.on.moleculeDisposal.next(disposalEvent)\n\t}\n\ttarget.molecules.delete(molecule.stringKey)\n\n\tconst trace = getTrace(new Error())\n\tstore.disposalTraces.add({ key: stringKey, trace })\n}\nexport function claimWithinStore<\n\tH extends Hierarchy,\n\tV extends Exclude<Vassal<H>, CompoundTypedKey>,\n\tA extends Above<V, H>,\n>(\n\tstore: Store,\n\tnewProvenance: A,\n\tclaim: Claim<V>,\n\texclusive?: `exclusive`,\n): Claim<V> {\n\tconst stringKey = stringifyJson(claim)\n\tconst target = newest(store)\n\tconst molecule = target.molecules.get(stringKey)\n\tif (!molecule) {\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === stringKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`molecule`,\n\t\t\tclaim,\n\t\t\t`claim failed:`,\n\t\t\t`Could not allocate to ${stringKey} in store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `\\n ${stringKey} was most recently disposed\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace for ${stringKey} was found.`,\n\t\t)\n\t\treturn claim\n\t}\n\n\tconst newProvenanceKey = stringifyJson(newProvenance as Canonical)\n\tconst newProvenanceMolecule = target.molecules.get(newProvenanceKey)\n\tif (!newProvenanceMolecule) {\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === newProvenanceKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`molecule`,\n\t\t\tclaim,\n\t\t\t`claim failed:`,\n\t\t\t`Could not allocate to ${newProvenanceKey} in store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `\\n ${newProvenanceKey} was most recently disposed\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace for ${newProvenanceKey} was found.`,\n\t\t)\n\t\treturn claim\n\t}\n\n\tconst priorProvenance = store.moleculeGraph\n\t\t.getRelationEntries({\n\t\t\tdownstreamMoleculeKey: molecule.stringKey,\n\t\t})\n\t\t.filter(([, { source }]) => source !== stringKey)\n\t\t.map(([key]) => parseJson(key))\n\tif (exclusive) {\n\t\ttarget.moleculeGraph.delete(stringKey)\n\t}\n\ttarget.moleculeGraph.set(\n\t\t{\n\t\t\tupstreamMoleculeKey: newProvenanceMolecule.stringKey,\n\t\t\tdownstreamMoleculeKey: molecule.stringKey,\n\t\t},\n\t\t{\n\t\t\tsource: newProvenanceMolecule.stringKey,\n\t\t},\n\t)\n\tconst transferEvent: MoleculeTransfer = {\n\t\ttype: `molecule_transfer`,\n\t\tkey: molecule.key,\n\t\tfrom: priorProvenance,\n\t\tto: [newProvenanceMolecule.key],\n\t}\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.updates.push(transferEvent)\n\t}\n\n\treturn claim\n}\n","import type {\n\tMoleculeCreation,\n\tMoleculeDisposal,\n\tMoleculeTransfer,\n\tReadableToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\n\nimport { disposeFromStore, findInStore } from \"../families\"\nimport {\n\tallocateIntoStore,\n\tclaimWithinStore,\n\tdeallocateFromStore,\n} from \"../molecule\"\nimport type { Store } from \"../store\"\n\nexport function ingestCreationEvent(\n\tupdate: StateCreation<any>,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`: {\n\t\t\tcreateInStore(update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `oldValue`: {\n\t\t\tdisposeFromStore(store, update.token)\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nexport function ingestDisposalEvent(\n\tupdate: StateDisposal<ReadableToken<any>>,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`: {\n\t\t\tdisposeFromStore(store, update.token)\n\t\t\tbreak\n\t\t}\n\t\tcase `oldValue`: {\n\t\t\tcreateInStore(update, store)\n\t\t\tif (update.subType === `atom`) {\n\t\t\t\tstore.valueMap.set(update.token.key, update.value)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nfunction createInStore(\n\tupdate: StateCreation<any> | StateDisposal<any>,\n\tstore: Store,\n): void {\n\tconst { family: familyMeta } = update.token\n\tif (familyMeta) {\n\t\tconst family = store.families.get(familyMeta.key)\n\t\tif (family) {\n\t\t\tfindInStore(store, family, parseJson(familyMeta.subKey))\n\t\t}\n\t}\n}\n\nexport function ingestMoleculeCreationEvent(\n\tupdate: MoleculeCreation,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\tallocateIntoStore<any, any, any>(store, update.provenance, update.key)\n\t\t\tbreak\n\n\t\tcase `oldValue`:\n\t\t\tdeallocateFromStore<any, any>(store, update.key)\n\t\t\tbreak\n\t}\n}\nexport function ingestMoleculeDisposalEvent(\n\tupdate: MoleculeDisposal,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\tdeallocateFromStore<any, any>(store, update.key)\n\t\t\tbreak\n\n\t\tcase `oldValue`:\n\t\t\t{\n\t\t\t\tconst provenanceJson = update.provenance.map(parseJson)\n\t\t\t\tallocateIntoStore<any, any, any>(store, provenanceJson, update.key)\n\t\t\t\tfor (const [familyKey, value] of update.values) {\n\t\t\t\t\tconst family = store.families.get(familyKey)\n\t\t\t\t\tif (family) {\n\t\t\t\t\t\tfindInStore(store, family, update.key)\n\t\t\t\t\t\tconst memberKey = `${familyKey}(${stringifyJson(update.key)})`\n\t\t\t\t\t\tstore.valueMap.set(memberKey, value)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t}\n}\nexport function ingestMoleculeTransferEvent(\n\tupdate: MoleculeTransfer,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\t{\n\t\t\t\tconst provenance = update.to.length === 1 ? update.to[0] : update.to\n\t\t\t\tclaimWithinStore<any, any, any>(\n\t\t\t\t\tstore,\n\t\t\t\t\tprovenance,\n\t\t\t\t\tupdate.key,\n\t\t\t\t\t`exclusive`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tbreak\n\t\tcase `oldValue`:\n\t\t\t{\n\t\t\t\tconst provenance =\n\t\t\t\t\tupdate.from.length === 1 ? update.from[0] : update.from\n\t\t\t\tclaimWithinStore<any, any, any>(\n\t\t\t\t\tstore,\n\t\t\t\t\tprovenance,\n\t\t\t\t\tupdate.key,\n\t\t\t\t\t`exclusive`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tbreak\n\t}\n}\n","import type { Store } from \"../store\"\nimport type { TimelineSelectorUpdate } from \"../timeline\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\n\nexport function ingestSelectorUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tselectorUpdate: TimelineSelectorUpdate<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? selectorUpdate.atomUpdates\n\t\t\t: selectorUpdate.atomUpdates.toReversed()\n\tfor (const atomUpdate of updates) {\n\t\tingestAtomUpdate(applying, atomUpdate, store)\n\t}\n}\n","import type { TransactionUpdate } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\nimport {\n\tingestCreationEvent,\n\tingestDisposalEvent,\n\tingestMoleculeCreationEvent,\n\tingestMoleculeDisposalEvent,\n\tingestMoleculeTransferEvent,\n} from \"./ingest-creation-disposal\"\n\nexport function ingestTransactionUpdate(\n\tapplying: `newValue` | `oldValue`,\n\ttransactionUpdate: TransactionUpdate<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? transactionUpdate.updates\n\t\t\t: [...transactionUpdate.updates].reverse()\n\tfor (const updateFromTransaction of updates) {\n\t\tswitch (updateFromTransaction.type) {\n\t\t\tcase `atom_update`:\n\t\t\tcase `selector_update`:\n\t\t\t\tingestAtomUpdate(applying, updateFromTransaction, store)\n\t\t\t\tbreak\n\t\t\tcase `state_creation`:\n\t\t\t\tingestCreationEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `state_disposal`:\n\t\t\t\tingestDisposalEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `molecule_creation`:\n\t\t\t\tingestMoleculeCreationEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `molecule_disposal`:\n\t\t\t\tingestMoleculeDisposalEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `molecule_transfer`:\n\t\t\t\tingestMoleculeTransferEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `transaction_update`:\n\t\t\t\tingestTransactionUpdate(applying, updateFromTransaction, store)\n\t\t\t\tbreak\n\t\t}\n\t}\n}\n","import type { Store } from \"../store\"\nimport type { RootStore } from \"./is-root-store\"\nimport { isRootStore } from \"./is-root-store\"\n\nexport function getContinuityKey(\n\tstore: RootStore,\n\ttransactionKey: string,\n): string | undefined {\n\tconst continuity =\n\t\tstore.transactionMeta.actionContinuities.getRelatedKey(transactionKey)\n\n\treturn continuity\n}\n\nexport function getEpochNumberOfContinuity(\n\tstore: RootStore,\n\tcontinuityKey: string,\n): number | undefined {\n\tconst epoch = store.transactionMeta.epoch.get(continuityKey)\n\treturn epoch\n}\n\nexport function getEpochNumberOfAction(\n\tstore: Store,\n\ttransactionKey: string,\n): number | undefined {\n\tconst isRoot = isRootStore(store)\n\tif (!isRoot) {\n\t\treturn undefined\n\t}\n\tconst continuityKey = getContinuityKey(store, transactionKey)\n\tif (continuityKey === undefined) {\n\t\treturn undefined\n\t}\n\treturn getEpochNumberOfContinuity(store, continuityKey)\n}\n","import type { Store } from \"../store\"\nimport { getContinuityKey } from \"./get-epoch-number\"\nimport { isRootStore } from \"./is-root-store\"\n\nexport function setEpochNumberOfContinuity(\n\tstore: Store,\n\tcontinuityKey: string,\n\tnewEpoch: number,\n): void {\n\tconst isRoot = isRootStore(store)\n\tif (isRoot && continuityKey) {\n\t\tstore.transactionMeta.epoch.set(continuityKey, newEpoch)\n\t}\n}\n\nexport function setEpochNumberOfAction(\n\tstore: Store,\n\ttransactionKey: string,\n\tnewEpoch: number,\n): void {\n\tconst isRoot = isRootStore(store)\n\tif (!isRoot) {\n\t\treturn\n\t}\n\tconst continuityKey = getContinuityKey(store, transactionKey)\n\n\tif (continuityKey !== undefined) {\n\t\tstore.transactionMeta.epoch.set(continuityKey, newEpoch)\n\t}\n}\n","import { ingestTransactionUpdate } from \"../ingest-updates\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Func } from \"../utility-types\"\nimport { isChildStore, isRootStore } from \"./is-root-store\"\nimport { setEpochNumberOfAction } from \"./set-epoch-number\"\n\nexport const applyTransaction = <F extends Func>(\n\toutput: ReturnType<F>,\n\tstore: Store,\n): void => {\n\tconst child = newest(store)\n\tconst { parent } = child\n\tif (\n\t\tparent === null ||\n\t\t!isChildStore(child) ||\n\t\tchild.transactionMeta?.phase !== `building`\n\t) {\n\t\tstore.logger.warn(\n\t\t\t`🐞`,\n\t\t\t`transaction`,\n\t\t\t`???`,\n\t\t\t`applyTransaction called outside of a transaction. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tchild.transactionMeta.phase = `applying`\n\tchild.transactionMeta.update.output = output\n\tparent.child = null\n\tparent.on.transactionApplying.next(child.transactionMeta)\n\tconst { updates } = child.transactionMeta.update\n\tstore.logger.info(\n\t\t`🛄`,\n\t\t`transaction`,\n\t\tchild.transactionMeta.update.key,\n\t\t`Applying transaction with ${updates.length} updates:`,\n\t\tupdates,\n\t)\n\n\tingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent)\n\n\tif (isRootStore(parent)) {\n\t\tsetEpochNumberOfAction(\n\t\t\tparent,\n\t\t\tchild.transactionMeta.update.key,\n\t\t\tchild.transactionMeta.update.epoch,\n\t\t)\n\t\tconst myTransaction = withdraw<F>(store, {\n\t\t\tkey: child.transactionMeta.update.key,\n\t\t\ttype: `transaction`,\n\t\t})\n\t\tmyTransaction?.subject.next(child.transactionMeta.update)\n\t\tstore.logger.info(\n\t\t\t`🛬`,\n\t\t\t`transaction`,\n\t\t\tchild.transactionMeta.update.key,\n\t\t\t`Finished applying transaction.`,\n\t\t)\n\t} else if (isChildStore(parent)) {\n\t\tparent.transactionMeta.update.updates.push(child.transactionMeta.update)\n\t}\n\tparent.on.transactionApplying.next(null)\n}\n","import type { Store } from \"../store\"\nimport { isRootStore } from \"./is-root-store\"\n\nexport function assignTransactionToContinuity(\n\tstore: Store,\n\tcontinuityKey: string,\n\ttransactionKey: string,\n): void {\n\tconst isRoot = isRootStore(store)\n\tif (!isRoot) {\n\t\treturn\n\t}\n\tconst { epoch, actionContinuities } = store.transactionMeta\n\tactionContinuities.set(continuityKey, transactionKey)\n\tif (!epoch.has(continuityKey)) {\n\t\tepoch.set(continuityKey, -1)\n\t}\n}\n","import type { Store } from \"./store\"\n\nexport type EnvironmentData = {\n\tstore: Store\n}\n\nexport function getEnvironmentData(store: Store): EnvironmentData {\n\treturn {\n\t\tstore,\n\t}\n}\n","export class LazyMap<K, V> extends Map<K, V> {\n\tpublic deleted: Set<K> = new Set()\n\tprotected readonly source: Map<K, V>\n\n\tpublic constructor(source: Map<K, V>) {\n\t\tsuper()\n\t\tthis.source = source\n\t}\n\n\tpublic get(key: K): V | undefined {\n\t\tconst has = super.has(key)\n\t\tif (has) {\n\t\t\treturn super.get(key)\n\t\t}\n\t\tif (!this.deleted.has(key) && this.source.has(key)) {\n\t\t\tconst value = this.source.get(key)\n\t\t\treturn value\n\t\t}\n\t\treturn undefined\n\t}\n\n\tpublic set(key: K, value: V): this {\n\t\tthis.deleted.delete(key)\n\t\treturn super.set(key, value)\n\t}\n\n\tpublic hasOwn(key: K): boolean {\n\t\treturn super.has(key)\n\t}\n\n\tpublic has(key: K): boolean {\n\t\treturn !this.deleted.has(key) && (super.has(key) || this.source.has(key))\n\t}\n\n\tpublic delete(key: K): boolean {\n\t\tthis.deleted.add(key)\n\t\treturn super.delete(key)\n\t}\n}\n","import type {\n\tdisposeState,\n\tfindState,\n\tgetState,\n\tresetState,\n\tsetState,\n} from \"atom.io\"\n\nimport { arbitrary } from \"../arbitrary\"\nimport { disposeFromStore, findInStore } from \"../families\"\nimport { getEnvironmentData } from \"../get-environment-data\"\nimport { getFromStore } from \"../get-state\"\nimport { Junction } from \"../junction\"\nimport { LazyMap } from \"../lazy-map\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { resetInStore, setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport type { Func } from \"../utility-types\"\nimport type { TransactionProgress } from \".\"\nimport { actUponStore, getEpochNumberOfAction } from \".\"\nimport type { ChildStore, RootStore } from \"./is-root-store\"\n\nexport const buildTransaction = (\n\tstore: Store,\n\tkey: string,\n\tparams: any[],\n\tid: string,\n): ChildStore => {\n\tconst parent = newest(store) as ChildStore | RootStore\n\tconst childBase: Omit<ChildStore, `transactionMeta`> = {\n\t\tparent,\n\t\tchild: null,\n\t\ton: parent.on,\n\t\tloggers: parent.loggers,\n\t\tlogger: parent.logger,\n\t\tconfig: parent.config,\n\t\tatoms: new LazyMap(parent.atoms),\n\t\tatomsThatAreDefault: new Set(parent.atomsThatAreDefault),\n\t\tfamilies: new LazyMap(parent.families),\n\t\tjoins: new LazyMap(parent.joins),\n\t\toperation: { open: false },\n\t\treadonlySelectors: new LazyMap(parent.readonlySelectors),\n\t\ttimelines: new LazyMap(parent.timelines),\n\t\ttimelineTopics: new Junction(parent.timelineTopics.toJSON()),\n\t\ttrackers: new Map(),\n\t\ttransactions: new LazyMap(parent.transactions),\n\t\tselectorAtoms: new Junction(parent.selectorAtoms.toJSON()),\n\t\tselectorGraph: new Junction(parent.selectorGraph.toJSON(), {\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t}),\n\t\twritableSelectors: new LazyMap(parent.writableSelectors),\n\t\tvalueMap: new LazyMap(parent.valueMap),\n\t\tdefaults: parent.defaults,\n\t\tdisposalTraces: store.disposalTraces.copy(),\n\t\tmolecules: new LazyMap(parent.molecules),\n\t\tmoleculeGraph: new Junction(parent.moleculeGraph.toJSON(), {\n\t\t\tmakeContentKey: parent.moleculeGraph.makeContentKey,\n\t\t}),\n\t\tmoleculeData: new Junction(parent.moleculeData.toJSON(), {\n\t\t\tmakeContentKey: parent.moleculeData.makeContentKey,\n\t\t}),\n\t\tmoleculeJoins: new Junction(parent.moleculeJoins.toJSON(), {\n\t\t\tmakeContentKey: parent.moleculeJoins.makeContentKey,\n\t\t}),\n\t\tmiscResources: new LazyMap(parent.miscResources),\n\t}\n\tconst epoch = getEpochNumberOfAction(store, key)\n\tconst transactionMeta: TransactionProgress<Func> = {\n\t\tphase: `building`,\n\t\tupdate: {\n\t\t\ttype: `transaction_update`,\n\t\t\tkey,\n\t\t\tid,\n\t\t\tepoch: epoch === undefined ? Number.NaN : epoch + 1,\n\t\t\tupdates: [],\n\t\t\tparams,\n\t\t\toutput: undefined,\n\t\t},\n\t\ttoolkit: {\n\t\t\tget: ((...ps: Parameters<typeof getState>) =>\n\t\t\t\tgetFromStore(child, ...ps)) as typeof getState,\n\t\t\tset: ((...ps: Parameters<typeof setState>) => {\n\t\t\t\tsetIntoStore(child, ...ps)\n\t\t\t}) as typeof setState,\n\t\t\treset: ((...ps: Parameters<typeof resetState>) => {\n\t\t\t\tresetInStore(child, ...ps)\n\t\t\t}) as typeof resetState,\n\t\t\trun: (token, identifier = arbitrary()) =>\n\t\t\t\tactUponStore(child, token, identifier),\n\t\t\tfind: ((...ps: Parameters<typeof findState>) =>\n\t\t\t\tfindInStore(store, ...ps)) as typeof findState,\n\t\t\tjson: (token) => getJsonToken(child, token),\n\t\t\tdispose: ((...ps: Parameters<typeof disposeState>) => {\n\t\t\t\tdisposeFromStore(child, ...ps)\n\t\t\t}) as typeof disposeState,\n\t\t\tenv: () => getEnvironmentData(child),\n\t\t},\n\t}\n\tconst child: ChildStore = Object.assign(childBase, {\n\t\ttransactionMeta,\n\t})\n\tparent.child = child\n\tstore.logger.info(\n\t\t`🛫`,\n\t\t`transaction`,\n\t\tkey,\n\t\t`Building transaction with params:`,\n\t\tparams,\n\t)\n\treturn child\n}\n","import type {\n\tTransactionOptions,\n\tTransactionToken,\n\tTransactionUpdate,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { Func } from \"../utility-types\"\nimport { abortTransaction } from \"./abort-transaction\"\nimport { applyTransaction } from \"./apply-transaction\"\nimport { buildTransaction } from \"./build-transaction\"\n\nexport type Transaction<F extends Func> = {\n\tkey: string\n\ttype: `transaction`\n\tinstall: (store: Store) => void\n\tsubject: Subject<TransactionUpdate<F>>\n\trun: (parameters: Parameters<F>, id?: string) => ReturnType<F>\n}\n\nexport function createTransaction<F extends Func>(\n\tstore: Store,\n\toptions: TransactionOptions<F>,\n): TransactionToken<F> {\n\tconst { key } = options\n\tconst transactionAlreadyExists = store.transactions.has(key)\n\tconst newTransaction: Transaction<F> = {\n\t\tkey,\n\t\ttype: `transaction`,\n\t\trun: (params: Parameters<F>, id: string) => {\n\t\t\tconst childStore = buildTransaction(store, key, params, id)\n\t\t\ttry {\n\t\t\t\tconst target = newest(store)\n\t\t\t\tconst { toolkit } = childStore.transactionMeta\n\t\t\t\tconst output = options.do(toolkit, ...params)\n\t\t\t\tapplyTransaction(output, target)\n\t\t\t\treturn output\n\t\t\t} catch (thrown) {\n\t\t\t\tabortTransaction(target)\n\t\t\t\tstore.logger.warn(`💥`, `transaction`, key, `caught:`, thrown)\n\t\t\t\tthrow thrown\n\t\t\t}\n\t\t},\n\t\tinstall: (s) => createTransaction(s, options),\n\t\tsubject: new Subject(),\n\t}\n\tconst target = newest(store)\n\ttarget.transactions.set(key, newTransaction)\n\tconst token = deposit(newTransaction)\n\tif (!transactionAlreadyExists) {\n\t\tstore.on.transactionCreation.next(token)\n\t}\n\treturn token\n}\n","import type { ActorToolkit, TransactionUpdate } from \"atom.io\"\n\nimport type { Junction } from \"../junction\"\nimport type { Func } from \"../utility-types\"\n\nexport * from \"./abort-transaction\"\nexport * from \"./act-upon-store\"\nexport * from \"./apply-transaction\"\nexport * from \"./assign-transaction-to-continuity\"\nexport * from \"./build-transaction\"\nexport * from \"./create-transaction\"\nexport * from \"./get-epoch-number\"\nexport * from \"./is-root-store\"\nexport * from \"./set-epoch-number\"\n\nexport const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const\nexport type TransactionPhase = (typeof TRANSACTION_PHASES)[number]\n\nexport type TransactionProgress<F extends Func> = {\n\tphase: `applying` | `building`\n\tupdate: TransactionUpdate<F>\n\ttoolkit: ActorToolkit\n}\n\nexport type TransactionEpoch = {\n\tepoch: Map<string, number>\n\tactionContinuities: Junction<`continuity`, string, `action`, string>\n}\n","import type {\n\tFamilyMetadata,\n\tWritableHeldSelectorOptions,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\n\nimport type { WritableHeldSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { markDone } from \"../operation\"\nimport { become } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { isRootStore } from \"../transaction\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createWritableHeldSelector = <T extends object>(\n\tstore: Store,\n\toptions: WritableHeldSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): WritableHeldSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst covered = new Set<string>()\n\tconst { key, const: constant } = options\n\tconst type = `writable_held_selector` as const\n\tconst setterToolkit = registerSelector(target, type, key, covered)\n\tconst { find, get, json } = setterToolkit\n\tconst getterToolkit = { find, get, json }\n\n\tconst getSelf = (getFn = options.get, innerTarget = newest(store)): T => {\n\t\tconst upstreamStates = innerTarget.selectorGraph.getRelationEntries({\n\t\t\tdownstreamSelectorKey: key,\n\t\t})\n\t\tfor (const [downstreamSelectorKey, { source }] of upstreamStates) {\n\t\t\tif (source !== key) {\n\t\t\t\tinnerTarget.selectorGraph.delete(downstreamSelectorKey, key)\n\t\t\t}\n\t\t}\n\t\tinnerTarget.selectorAtoms.delete(key)\n\t\tgetFn(getterToolkit, constant)\n\t\tcacheValue(innerTarget, key, constant, subject)\n\t\tstore.logger.info(`✨`, type, key, `=`, constant)\n\t\tcovered.clear()\n\t\treturn constant\n\t}\n\n\tconst setSelf = (next: T | ((oldValue: T) => T)): void => {\n\t\tconst innerTarget = newest(store)\n\t\tconst oldValue = getSelf(options.get, innerTarget)\n\t\tconst newValue = become(next)(oldValue)\n\t\tstore.logger.info(`📝`, type, key, `set (`, oldValue, `->`, newValue, `)`)\n\t\tcacheValue(innerTarget, key, newValue, subject)\n\t\tmarkDone(innerTarget, key)\n\t\tif (isRootStore(innerTarget)) {\n\t\t\tsubject.next({ newValue, oldValue })\n\t\t}\n\t\toptions.set(setterToolkit, newValue)\n\t}\n\tconst mySelector: WritableHeldSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritableHeldSelector(s, options, family),\n\t\tget: getSelf,\n\t\tset: setSelf,\n\t\t...(family && { family }),\n\t}\n\ttarget.writableSelectors.set(key, mySelector)\n\t// const initialValue = getSelf()\n\n\tconst token: WritableHeldSelectorToken<T> = { key, type }\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tWritablePureSelectorOptions,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\n\nimport type { WritablePureSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { markDone } from \"../operation\"\nimport { become } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { isRootStore } from \"../transaction\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createWritablePureSelector = <T>(\n\tstore: Store,\n\toptions: WritablePureSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): WritablePureSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst covered = new Set<string>()\n\tconst key = options.key\n\tconst type = `writable_pure_selector` as const\n\tconst setterToolkit = registerSelector(target, type, key, covered)\n\tconst { find, get, json } = setterToolkit\n\tconst getterToolkit = { find, get, json }\n\n\tconst getSelf = (getFn = options.get, innerTarget = newest(store)): T => {\n\t\tconst upstreamStates = innerTarget.selectorGraph.getRelationEntries({\n\t\t\tdownstreamSelectorKey: key,\n\t\t})\n\t\tfor (const [downstreamSelectorKey, { source }] of upstreamStates) {\n\t\t\tif (source !== key) {\n\t\t\t\tinnerTarget.selectorGraph.delete(downstreamSelectorKey, key)\n\t\t\t}\n\t\t}\n\t\tinnerTarget.selectorAtoms.delete(key)\n\t\tconst value = getFn(getterToolkit)\n\t\tconst cached = cacheValue(innerTarget, key, value, subject)\n\t\tstore.logger.info(`✨`, type, key, `=`, cached)\n\t\tcovered.clear()\n\t\treturn value\n\t}\n\n\tconst setSelf = (next: T | ((oldValue: T) => T)): void => {\n\t\tconst innerTarget = newest(store)\n\t\tconst oldValue = getSelf(options.get, innerTarget)\n\t\tconst newValue = become(next)(oldValue)\n\t\tstore.logger.info(`📝`, type, key, `set (`, oldValue, `->`, newValue, `)`)\n\t\tcacheValue(innerTarget, options.key, newValue, subject)\n\t\tmarkDone(innerTarget, options.key)\n\t\tif (isRootStore(innerTarget)) {\n\t\t\tsubject.next({ newValue, oldValue })\n\t\t}\n\t\toptions.set(setterToolkit, newValue)\n\t}\n\tconst mySelector: WritablePureSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritablePureSelector(s, options, family),\n\t\tget: getSelf,\n\t\tset: setSelf,\n\t\t...(family && { family }),\n\t}\n\ttarget.writableSelectors.set(key, mySelector)\n\tconst initialValue = getSelf()\n\tstore.logger.info(`✨`, mySelector.type, mySelector.key, `=`, initialValue)\n\tconst token: WritablePureSelectorToken<T> = {\n\t\tkey,\n\t\ttype,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\treturn token\n}\n","import type {\n\tReadonlyHeldSelectorOptions,\n\tReadonlyHeldSelectorToken,\n\tReadonlyPureSelectorOptions,\n\tReadonlyPureSelectorToken,\n\tWritableHeldSelectorOptions,\n\tWritableHeldSelectorToken,\n\tWritablePureSelectorOptions,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { createReadonlyHeldSelector } from \"./create-readonly-held-selector\"\nimport { createReadonlyPureSelector } from \"./create-readonly-pure-selector\"\nimport { createWritableHeldSelector } from \"./create-writable-held-selector\"\nimport { createWritablePureSelector } from \"./create-writable-pure-selector\"\n\nexport function createStandaloneSelector<T extends object>(\n\tstore: Store,\n\toptions: WritableHeldSelectorOptions<T>,\n): WritableHeldSelectorToken<T>\nexport function createStandaloneSelector<T extends object>(\n\tstore: Store,\n\toptions: ReadonlyHeldSelectorOptions<T>,\n): ReadonlyHeldSelectorToken<T>\nexport function createStandaloneSelector<T>(\n\tstore: Store,\n\toptions: WritablePureSelectorOptions<T>,\n): WritablePureSelectorToken<T>\nexport function createStandaloneSelector<T>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorOptions<T>,\n): ReadonlyPureSelectorToken<T>\nexport function createStandaloneSelector(\n\tstore: Store,\n\toptions:\n\t\t| ReadonlyHeldSelectorOptions<any>\n\t\t| ReadonlyPureSelectorOptions<any>\n\t\t| WritableHeldSelectorOptions<any>\n\t\t| WritablePureSelectorOptions<any>,\n):\n\t| ReadonlyHeldSelectorToken<any>\n\t| ReadonlyPureSelectorToken<any>\n\t| WritableHeldSelectorToken<any>\n\t| WritablePureSelectorToken<any> {\n\tconst isWritable = `set` in options\n\tconst isHeld = `const` in options\n\n\tif (isHeld && isWritable) {\n\t\tconst state = createWritableHeldSelector(store, options, undefined)\n\t\tstore.on.selectorCreation.next(state)\n\t\treturn state\n\t}\n\tif (isHeld) {\n\t\tconst state = createReadonlyHeldSelector(store, options, undefined)\n\t\tstore.on.selectorCreation.next(state)\n\t\treturn state\n\t}\n\tif (isWritable) {\n\t\tconst state = createWritablePureSelector(store, options, undefined)\n\t\tstore.on.selectorCreation.next(state)\n\t\treturn state\n\t}\n\tconst state = createReadonlyPureSelector(store, options, undefined)\n\tstore.on.selectorCreation.next(state)\n\treturn state\n}\n","import type { SelectorFamilyToken, SelectorToken } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { isChildStore, newest, withdraw } from \"..\"\n\nexport function disposeSelector(\n\tstore: Store,\n\tselectorToken: SelectorToken<unknown>,\n): void {\n\tconst target = newest(store)\n\tconst { key, type } = selectorToken\n\tconst selector = withdraw(target, selectorToken)\n\tif (!selector.family) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttype,\n\t\t\tkey,\n\t\t\t`Standalone selectors cannot be disposed.`,\n\t\t)\n\t} else {\n\t\tconst molecule = target.molecules.get(selector.family.subKey)\n\t\tif (molecule) {\n\t\t\ttarget.moleculeData.delete(selector.family.subKey, selector.family.key)\n\t\t}\n\t\tlet familyToken: SelectorFamilyToken<any, any>\n\t\tswitch (selectorToken.type) {\n\t\t\tcase `writable_held_selector`:\n\t\t\t\t{\n\t\t\t\t\ttarget.writableSelectors.delete(key)\n\t\t\t\t\tfamilyToken = {\n\t\t\t\t\t\tkey: selector.family.key,\n\t\t\t\t\t\ttype: `writable_held_selector_family`,\n\t\t\t\t\t}\n\t\t\t\t\tconst family = withdraw(store, familyToken)\n\t\t\t\t\tfamily.subject.next({\n\t\t\t\t\t\ttype: `state_disposal`,\n\t\t\t\t\t\tsubType: `selector`,\n\t\t\t\t\t\ttoken: selectorToken,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `writable_pure_selector`:\n\t\t\t\t{\n\t\t\t\t\ttarget.writableSelectors.delete(key)\n\t\t\t\t\tfamilyToken = {\n\t\t\t\t\t\tkey: selector.family.key,\n\t\t\t\t\t\ttype: `writable_pure_selector_family`,\n\t\t\t\t\t}\n\t\t\t\t\tconst family = withdraw(store, familyToken)\n\t\t\t\t\tfamily.subject.next({\n\t\t\t\t\t\ttype: `state_disposal`,\n\t\t\t\t\t\tsubType: `selector`,\n\t\t\t\t\t\ttoken: selectorToken,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `readonly_held_selector`:\n\t\t\t\t{\n\t\t\t\t\ttarget.readonlySelectors.delete(key)\n\t\t\t\t\tfamilyToken = {\n\t\t\t\t\t\tkey: selector.family.key,\n\t\t\t\t\t\ttype: `readonly_held_selector_family`,\n\t\t\t\t\t}\n\t\t\t\t\tconst family = withdraw(store, familyToken)\n\t\t\t\t\tfamily.subject.next({\n\t\t\t\t\t\ttype: `state_disposal`,\n\t\t\t\t\t\tsubType: `selector`,\n\t\t\t\t\t\ttoken: selectorToken,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `readonly_pure_selector`:\n\t\t\t\t{\n\t\t\t\t\ttarget.readonlySelectors.delete(key)\n\t\t\t\t\tfamilyToken = {\n\t\t\t\t\t\tkey: selector.family.key,\n\t\t\t\t\t\ttype: `readonly_pure_selector_family`,\n\t\t\t\t\t}\n\t\t\t\t\tconst family = withdraw(store, familyToken)\n\t\t\t\t\tfamily.subject.next({\n\t\t\t\t\t\ttype: `state_disposal`,\n\t\t\t\t\t\tsubType: `selector`,\n\t\t\t\t\t\ttoken: selectorToken,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\n\t\ttarget.valueMap.delete(key)\n\t\ttarget.selectorAtoms.delete(key)\n\t\ttarget.selectorGraph.delete(key)\n\t\tstore.logger.info(`🔥`, selectorToken.type, key, `deleted`)\n\t\tif (isChildStore(target) && target.transactionMeta.phase === `building`) {\n\t\t\ttarget.transactionMeta.update.updates.push({\n\t\t\t\ttype: `state_disposal`,\n\t\t\t\tsubType: `selector`,\n\t\t\t\ttoken: selectorToken,\n\t\t\t})\n\t\t} else {\n\t\t\tstore.on.selectorDisposal.next(selectorToken)\n\t\t}\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tfindState,\n\tgetState,\n\tReadonlyPureSelectorFamilyOptions,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tprettyPrintTokenType,\n\ttype ReadonlyPureSelectorFamily,\n} from \"..\"\nimport { newest } from \"../lineage\"\nimport { createReadonlyPureSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createReadonlyPureSelectorFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): ReadonlyPureSelectorFamilyToken<T, K> {\n\tconst familyKey = options.key\n\tconst type = `readonly_pure_selector_family`\n\n\tconst familyToken = {\n\t\tkey: familyKey,\n\t\ttype,\n\t} as const satisfies ReadonlyPureSelectorFamilyToken<T, K>\n\n\tconst existing = store.families.get(familyKey)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\ttype,\n\t\t\tfamilyKey,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\n\tconst subject = new Subject<\n\t\t| StateCreation<ReadonlyPureSelectorToken<T>>\n\t\t| StateDisposal<ReadonlyPureSelectorToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): ReadonlyPureSelectorToken<T> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst token = createReadonlyPureSelector(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\tkey: fullKey,\n\t\t\t\tget: options.get(key),\n\t\t\t},\n\t\t\tfamily,\n\t\t)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst readonlySelectorFamily = Object.assign(familyFunction, familyToken, {\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlyPureSelectorFamily(s, options),\n\t\tdefault: (key: K) => {\n\t\t\tconst getFn = options.get(key)\n\t\t\treturn getFn({\n\t\t\t\tget: ((...args: Parameters<typeof getState>) =>\n\t\t\t\t\tgetFromStore(store, ...args)) as typeof getState,\n\t\t\t\tfind: ((...args: Parameters<typeof findState>) =>\n\t\t\t\t\tfindInStore(store, ...args)) as typeof findState,\n\t\t\t\tjson: (token) => getJsonToken(store, token),\n\t\t\t})\n\t\t},\n\t}) satisfies ReadonlyPureSelectorFamily<T, K>\n\n\tstore.families.set(familyKey, readonlySelectorFamily)\n\treturn familyToken\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyHeldSelectorFamilyOptions,\n\tReadonlyHeldSelectorFamilyToken,\n\tReadonlyHeldSelectorToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ReadonlyHeldSelectorFamily } from \"..\"\nimport { prettyPrintTokenType } from \"..\"\nimport { newest } from \"../lineage\"\nimport { createReadonlyHeldSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createReadonlyHeldSelectorFamily<\n\tT extends object,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\toptions: ReadonlyHeldSelectorFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): ReadonlyHeldSelectorFamilyToken<T, K> {\n\tconst familyKey = options.key\n\tconst type = `readonly_held_selector_family`\n\n\tconst familyToken = {\n\t\tkey: familyKey,\n\t\ttype,\n\t} as const satisfies ReadonlyHeldSelectorFamilyToken<T, K>\n\n\tconst existing = store.families.get(familyKey)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\ttype,\n\t\t\tfamilyKey,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\n\tconst subject = new Subject<\n\t\t| StateCreation<ReadonlyHeldSelectorToken<T>>\n\t\t| StateDisposal<ReadonlyHeldSelectorToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): ReadonlyHeldSelectorToken<T> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst token = createReadonlyHeldSelector(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\tkey: fullKey,\n\t\t\t\tconst: options.const(key),\n\t\t\t\tget: options.get(key),\n\t\t\t},\n\t\t\tfamily,\n\t\t)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst readonlySelectorFamily = Object.assign(familyFunction, familyToken, {\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlyHeldSelectorFamily(s, options),\n\t\tdefault: options.const,\n\t}) satisfies ReadonlyHeldSelectorFamily<T, K>\n\n\tstore.families.set(familyKey, readonlySelectorFamily)\n\treturn familyToken\n}\n","import type {\n\tFamilyMetadata,\n\tStateCreation,\n\tStateDisposal,\n\tWritableHeldSelectorFamilyOptions,\n\tWritableHeldSelectorFamilyToken,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { prettyPrintTokenType, type WritableHeldSelectorFamily } from \"..\"\nimport { newest } from \"../lineage\"\nimport { createWritableHeldSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createWritableHeldSelectorFamily<\n\tT extends object,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\toptions: WritableHeldSelectorFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): WritableHeldSelectorFamilyToken<T, K> {\n\tconst familyKey = options.key\n\tconst type = `writable_held_selector_family`\n\n\tconst familyToken = {\n\t\tkey: familyKey,\n\t\ttype,\n\t} as const satisfies WritableHeldSelectorFamilyToken<T, K>\n\n\tconst existing = store.families.get(familyKey)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\ttype,\n\t\t\tfamilyKey,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\tconst subject = new Subject<\n\t\t| StateCreation<WritableHeldSelectorToken<T>>\n\t\t| StateDisposal<WritableHeldSelectorToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): WritableHeldSelectorToken<T> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst token = createWritableHeldSelector(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\tkey: fullKey,\n\t\t\t\tconst: options.const(key),\n\t\t\t\tget: options.get(key),\n\t\t\t\tset: options.set(key),\n\t\t\t},\n\t\t\tfamily,\n\t\t)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst selectorFamily = Object.assign(familyFunction, familyToken, {\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritableHeldSelectorFamily(s, options),\n\t\tdefault: options.const,\n\t}) satisfies WritableHeldSelectorFamily<T, K>\n\n\tstore.families.set(familyKey, selectorFamily)\n\treturn familyToken\n}\n","import type {\n\tFamilyMetadata,\n\tfindState,\n\tgetState,\n\tStateCreation,\n\tStateDisposal,\n\tWritablePureSelectorFamilyOptions,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tprettyPrintTokenType,\n\ttype WritablePureSelectorFamily,\n} from \"..\"\nimport { newest } from \"../lineage\"\nimport { createWritablePureSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createWritablePureSelectorFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: WritablePureSelectorFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): WritablePureSelectorFamilyToken<T, K> {\n\tconst familyKey = options.key\n\tconst type = `writable_pure_selector_family`\n\n\tconst familyToken = {\n\t\tkey: familyKey,\n\t\ttype,\n\t} as const satisfies WritablePureSelectorFamilyToken<T, K>\n\n\tconst existing = store.families.get(familyKey)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\ttype,\n\t\t\tfamilyKey,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\tconst subject = new Subject<\n\t\t| StateCreation<WritablePureSelectorToken<T>>\n\t\t| StateDisposal<WritablePureSelectorToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): WritablePureSelectorToken<T> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst token = createWritablePureSelector(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\tkey: fullKey,\n\t\t\t\tget: options.get(key),\n\t\t\t\tset: options.set(key),\n\t\t\t},\n\t\t\tfamily,\n\t\t)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst selectorFamily = Object.assign(familyFunction, familyToken, {\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritablePureSelectorFamily(s, options),\n\t\tdefault: (key: K) => {\n\t\t\tconst getFn = options.get(key)\n\t\t\treturn getFn({\n\t\t\t\tget: ((...args: Parameters<typeof getState>) =>\n\t\t\t\t\tgetFromStore(store, ...args)) as typeof getState,\n\t\t\t\tfind: ((...args: Parameters<typeof findState>) =>\n\t\t\t\t\tfindInStore(store, ...args)) as typeof findState,\n\t\t\t\tjson: (token) => getJsonToken(store, token),\n\t\t\t})\n\t\t},\n\t}) satisfies WritablePureSelectorFamily<T, K>\n\n\tstore.families.set(familyKey, selectorFamily)\n\treturn familyToken\n}\n","import type {\n\tReadonlyHeldSelectorFamilyOptions,\n\tReadonlyHeldSelectorFamilyToken,\n\tReadonlyPureSelectorFamilyOptions,\n\tReadonlyPureSelectorFamilyToken,\n\tSelectorFamilyToken,\n\tWritableHeldSelectorFamilyOptions,\n\tWritableHeldSelectorFamilyToken,\n\tWritablePureSelectorFamilyOptions,\n\tWritablePureSelectorFamilyToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { createReadonlyHeldSelectorFamily } from \"./create-readonly-held-selector-family\"\nimport { createReadonlyPureSelectorFamily } from \"./create-readonly-pure-selector-family\"\nimport { createWritableHeldSelectorFamily } from \"./create-writable-held-selector-family\"\nimport { createWritablePureSelectorFamily } from \"./create-writable-pure-selector-family\"\n\nexport function createSelectorFamily<T extends object, K extends Canonical>(\n\tstore: Store,\n\toptions: WritableHeldSelectorFamilyOptions<T, K>,\n): WritableHeldSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T extends object, K extends Canonical>(\n\tstore: Store,\n\toptions: ReadonlyHeldSelectorFamilyOptions<T, K>,\n): ReadonlyHeldSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: WritablePureSelectorFamilyOptions<T, K>,\n): WritablePureSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorFamilyOptions<T, K>,\n): ReadonlyPureSelectorFamilyToken<T, K>\nexport function createSelectorFamily(\n\tstore: Store,\n\toptions:\n\t\t| ReadonlyHeldSelectorFamilyOptions<any, any>\n\t\t| ReadonlyPureSelectorFamilyOptions<any, any>\n\t\t| WritableHeldSelectorFamilyOptions<any, any>\n\t\t| WritablePureSelectorFamilyOptions<any, any>,\n): SelectorFamilyToken<any, any> {\n\tconst isWritable = `set` in options\n\tconst isHeld = `const` in options\n\n\tif (isHeld && isWritable) {\n\t\treturn createWritableHeldSelectorFamily(store, options, undefined)\n\t}\n\tif (isHeld) {\n\t\treturn createReadonlyHeldSelectorFamily(store, options, undefined)\n\t}\n\tif (isWritable) {\n\t\treturn createWritablePureSelectorFamily(store, options)\n\t}\n\treturn createReadonlyPureSelectorFamily(store, options)\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport { NotFoundError } from \"../not-found-error\"\nimport type { Store } from \"../store\"\nimport { isChildStore, isRootStore } from \"../transaction\"\n\nexport function initFamilyMemberInStore<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, J, K>,\n\tkey: Key,\n): MutableAtomToken<T, J, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n): AtomToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritablePureSelectorToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n): SelectorToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T, K>\n\nexport function initFamilyMemberInStore(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n): ReadableToken<any> {\n\tconst family = store.families.get(token.key)\n\tif (family === undefined) {\n\t\tthrow new NotFoundError(token, store)\n\t}\n\tconst state = family(key)\n\tconst target = newest(store)\n\tif (state.family) {\n\t\tif (isRootStore(target)) {\n\t\t\tswitch (state.type) {\n\t\t\t\tcase `atom`:\n\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\tstore.on.atomCreation.next(state)\n\t\t\t\t\tbreak\n\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\tcase `readonly_pure_selector`:\n\t\t\t\tcase `writable_held_selector`:\n\t\t\t\tcase `readonly_held_selector`:\n\t\t\t\t\tstore.on.selectorCreation.next(state)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t} else if (\n\t\t\tisChildStore(target) &&\n\t\t\ttarget.on.transactionApplying.state === null\n\t\t) {\n\t\t\ttarget.transactionMeta.update.updates.push({\n\t\t\t\ttype: `state_creation`,\n\t\t\t\ttoken: state,\n\t\t\t})\n\t\t}\n\t}\n\treturn state\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { Molecule, ReadableState } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport { deposit, type Store } from \"../store\"\n\nexport function seekInStore<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, J, K>,\n\tkey: Key,\n): MutableAtomToken<T, J, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n): AtomToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritablePureSelectorToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n): SelectorToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T, K> | undefined\n\nexport function seekInStore(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n): ReadableToken<any> | undefined {\n\tconst subKey = stringifyJson(key)\n\tconst fullKey = `${token.key}(${subKey})`\n\tconst target = newest(store)\n\tlet state: Molecule<any> | ReadableState<any> | undefined\n\tswitch (token.type) {\n\t\tcase `atom_family`:\n\t\tcase `mutable_atom_family`:\n\t\t\tstate = target.atoms.get(fullKey)\n\t\t\tbreak\n\t\tcase `writable_held_selector_family`:\n\t\tcase `writable_pure_selector_family`:\n\t\t\tstate = target.writableSelectors.get(fullKey)\n\t\t\tbreak\n\t\tcase `readonly_held_selector_family`:\n\t\tcase `readonly_pure_selector_family`:\n\t\t\tstate = target.readonlySelectors.get(fullKey)\n\t\t\tbreak\n\t}\n\tif (state) {\n\t\treturn deposit(state)\n\t}\n\treturn state\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport { type Canonical, type Json, stringifyJson } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport { counterfeit, type Store } from \"../store\"\nimport { initFamilyMemberInStore } from \"./init-family-member\"\nimport { seekInStore } from \"./seek-in-store\"\n\nexport function findInStore<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, J, K>,\n\tkey: Key,\n): MutableAtomToken<T, J, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n): AtomToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritablePureSelectorToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n): SelectorToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T, K>\n\nexport function findInStore(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n): ReadableToken<any> {\n\tlet state = seekInStore(store, token, key)\n\tif (state) {\n\t\treturn state\n\t}\n\tconst stringKey = stringifyJson(key)\n\tconst molecule = store.molecules.get(stringKey)\n\tif (!molecule && store.config.lifespan === `immortal`) {\n\t\tconst fakeToken = counterfeit(token, key)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\tfakeToken.type,\n\t\t\tfakeToken.key,\n\t\t\t`was not found in store \"${store.config.name}\"; returned a counterfeit token.`,\n\t\t)\n\t\treturn fakeToken\n\t}\n\tstate = initFamilyMemberInStore(store, token, key)\n\tif (molecule) {\n\t\tconst target = newest(store)\n\t\ttarget.moleculeData.set(stringKey, token.key)\n\t}\n\treturn state\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { disposeAtom } from \"../atom\"\nimport { disposeSelector } from \"../selector\"\nimport { type Store, withdraw } from \"../store\"\nimport { findInStore } from \"./find-in-store\"\n\nexport function disposeFromStore(store: Store, token: ReadableToken<any>): void\n\nexport function disposeFromStore<K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, K>,\n\tkey: K,\n): void\n\nexport function disposeFromStore(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<any, any>, key: Canonical]\n\t\t| [token: ReadableToken<any>]\n): void {\n\tlet token: ReadableToken<any>\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t} else {\n\t\tconst family = params[0]\n\t\tconst key = params[1]\n\t\tconst maybeToken = findInStore(store, family, key)\n\t\ttoken = maybeToken\n\t}\n\ttry {\n\t\twithdraw(store, token)\n\t} catch (_) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`could not be disposed because it was not found in the store \"${store.config.name}\".`,\n\t\t)\n\t\treturn\n\t}\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tdisposeAtom(store, token)\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\tcase `readonly_held_selector`:\n\t\t\tdisposeSelector(store, token)\n\t\t\tbreak\n\t}\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { readOrComputeValue } from \"./read-or-compute-value\"\n\nexport function getFromStore<T>(store: Store, token: ReadableToken<T>): T\n\nexport function getFromStore<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: K,\n): T\n\nexport function getFromStore(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<any, any>, key: Canonical]\n\t\t| [token: ReadableToken<any>]\n): any {\n\tlet token: ReadableToken<any>\n\tlet family: ReadableFamilyToken<any, Canonical> | null\n\tlet key: Canonical | null\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\ttoken = findInStore(store, family, key)\n\t}\n\tif (`counterfeit` in token && `family` in token) {\n\t\t// biome-ignore lint/style/noNonNullAssertion: family must be present\n\t\tfamily = store.families.get(token.family.key)!\n\t\tconst subKey = token.family.subKey\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === subKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`could not be retrieved because it was not found in the store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `This state was previously disposed:\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace was found.`,\n\t\t)\n\t\tswitch (family.type) {\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\tcase `readonly_pure_selector_family`:\n\t\t\tcase `writable_pure_selector_family`:\n\t\t\tcase `readonly_held_selector_family`:\n\t\t\tcase `writable_held_selector_family`: {\n\t\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\t\treturn store.defaults.get(token.family.key)\n\t\t\t\t}\n\t\t\t\t3\n\t\t\t\tconst defaultValue = withdraw(store, family).default(subKey)\n\t\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\t\treturn defaultValue\n\t\t\t}\n\t\t}\n\t}\n\n\treturn readOrComputeValue(store, withdraw(store, token))\n}\n","import type { ReadableToken, StateUpdate, UpdateHandler } from \"atom.io\"\n\nimport { readOrComputeValue } from \"../get-state\"\nimport { traceRootSelectorAtoms } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { subscribeToRootDependency } from \"./subscribe-to-root-atoms\"\n\nexport function subscribeToState<T>(\n\tstore: Store,\n\ttoken: ReadableToken<T>,\n\tkey: string,\n\thandleUpdate: UpdateHandler<T>,\n): () => void {\n\tfunction safelyHandleUpdate(update: StateUpdate<any>): void {\n\t\tif (store.operation.open) {\n\t\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t\t`state subscription ${key}`,\n\t\t\t\t() => {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\thandleUpdate(update)\n\t\t\t\t},\n\t\t\t)\n\t\t} else {\n\t\t\thandleUpdate(update)\n\t\t}\n\t}\n\tconst state = withdraw(store, token)\n\tstore.logger.info(`👀`, state.type, state.key, `Adding subscription \"${key}\"`)\n\tconst isSelector =\n\t\tstate.type === `writable_pure_selector` ||\n\t\tstate.type === `readonly_pure_selector`\n\tconst rootSubs = new Map<string, () => void>()\n\tlet updateHandler: UpdateHandler<T> = safelyHandleUpdate\n\tif (isSelector) {\n\t\treadOrComputeValue(store, state)\n\t\tfor (const [atomKey, atom] of traceRootSelectorAtoms(store, state.key)) {\n\t\t\trootSubs.set(atomKey, subscribeToRootDependency(store, state, atom))\n\t\t}\n\t\tupdateHandler = function updateRootsBeforeHandlingUpdate(update) {\n\t\t\tconst dependencies = traceRootSelectorAtoms(store, state.key)\n\t\t\tfor (const [previousRootKey, unsub] of rootSubs) {\n\t\t\t\tconst currentRoot = dependencies.get(previousRootKey)\n\t\t\t\tif (currentRoot) {\n\t\t\t\t\tdependencies.delete(previousRootKey)\n\t\t\t\t} else {\n\t\t\t\t\tunsub()\n\t\t\t\t\trootSubs.delete(previousRootKey)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [atomKey, atom] of dependencies) {\n\t\t\t\trootSubs.set(atomKey, subscribeToRootDependency(store, state, atom))\n\t\t\t}\n\t\t\tsafelyHandleUpdate(update)\n\t\t}\n\t}\n\tconst mainUnsubFunction = state.subject.subscribe(key, updateHandler)\n\tconst unsubscribe = () => {\n\t\tstore.logger.info(\n\t\t\t`🙈`,\n\t\t\tstate.type,\n\t\t\tstate.key,\n\t\t\t`Removing subscription \"${key}\"`,\n\t\t)\n\t\tmainUnsubFunction()\n\t\tfor (const unsubFromDependency of rootSubs.values()) {\n\t\t\tunsubFromDependency()\n\t\t}\n\t}\n\n\treturn unsubscribe\n}\n","import type { TimelineManageable, TimelineToken, TimelineUpdate } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { withdraw } from \"..\"\n\nexport const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(\n\tstore: Store,\n\ttoken: TimelineToken<ManagedAtom>,\n\tkey: string,\n\thandleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void,\n): (() => void) => {\n\tconst tl = withdraw(store, token)\n\tstore.logger.info(`👀`, `timeline`, token.key, `Adding subscription \"${key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(\n\t\t\t`🙈`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Removing subscription \"${key}\" from timeline`,\n\t\t)\n\t\tunsubscribe()\n\t}\n}\n","import type { TransactionToken, TransactionUpdateHandler } from \"atom.io\"\n\nimport type { Func, Store } from \"..\"\nimport { withdraw } from \"..\"\n\nexport const subscribeToTransaction = <F extends Func>(\n\tstore: Store,\n\ttoken: TransactionToken<F>,\n\tkey: string,\n\thandleUpdate: TransactionUpdateHandler<F>,\n): (() => void) => {\n\tconst tx = withdraw(store, token)\n\tstore.logger.info(\n\t\t`👀`,\n\t\t`transaction`,\n\t\ttoken.key,\n\t\t`Adding subscription \"${key}\"`,\n\t)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(\n\t\t\t`🙈`,\n\t\t\t`transaction`,\n\t\t\ttoken.key,\n\t\t\t`Removing subscription \"${key}\"`,\n\t\t)\n\t\tunsubscribe()\n\t}\n}\n","import type { FamilyMetadata, MutableAtomToken, RegularAtomToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"..\"\nimport {\n\tgetFromStore,\n\tnewest,\n\tsetIntoStore,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n} from \"..\"\nimport { createRegularAtom } from \"../atom\"\nimport { isChildStore } from \"../transaction/is-root-store\"\nimport type { Transceiver } from \"./transceiver\"\n\n/**\n * @internal Give the tracker a transceiver state and a store, and it will\n * subscribe to the transceiver's inner value. When the inner value changes,\n * the tracker will update its own state to reflect the change.\n */\nexport class Tracker<Mutable extends Transceiver<any>> {\n\tprivate initializeState(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store,\n\t): RegularAtomToken<\n\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t> {\n\t\tconst latestUpdateStateKey = `*${mutableState.key}`\n\t\tstore.atoms.delete(latestUpdateStateKey)\n\t\tstore.valueMap.delete(latestUpdateStateKey)\n\t\tconst familyMetaData: FamilyMetadata | undefined = mutableState.family\n\t\t\t? {\n\t\t\t\t\tkey: `*${mutableState.family.key}`,\n\t\t\t\t\tsubKey: mutableState.family.subKey,\n\t\t\t\t}\n\t\t\t: undefined\n\t\tconst latestUpdateState = createRegularAtom<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: latestUpdateStateKey,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\tfamilyMetaData,\n\t\t)\n\t\tif (store.parent?.valueMap.has(latestUpdateStateKey)) {\n\t\t\tconst parentValue = store.parent.valueMap.get(latestUpdateStateKey)\n\t\t\tstore.valueMap.set(latestUpdateStateKey, parentValue)\n\t\t}\n\n\t\treturn latestUpdateState\n\t}\n\n\tprivate unsubscribeFromInnerValue!: () => void\n\tprivate unsubscribeFromState!: () => void\n\tprivate observeCore(\n\t\tmutableState: MutableAtomToken<Mutable, any>,\n\t\tlatestUpdateState: RegularAtomToken<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst subscriptionKey = `tracker:${target.config.name}:${\n\t\t\tisChildStore(target) ? target.transactionMeta.update.key : `main`\n\t\t}:${mutableState.key}`\n\t\tconst originalInnerValue = getFromStore(target, mutableState)\n\t\tthis.unsubscribeFromInnerValue = originalInnerValue.subscribe(\n\t\t\tsubscriptionKey,\n\t\t\t(update) => {\n\t\t\t\tsetIntoStore(target, latestUpdateState, update)\n\t\t\t},\n\t\t)\n\t\tthis.unsubscribeFromState = subscribeToState(\n\t\t\ttarget,\n\t\t\tmutableState,\n\t\t\tsubscriptionKey,\n\t\t\t(update) => {\n\t\t\t\tif (update.newValue !== update.oldValue) {\n\t\t\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\t\t\tthis.unsubscribeFromInnerValue = update.newValue.subscribe(\n\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\t(transceiverUpdate) => {\n\t\t\t\t\t\t\tsetIntoStore(target, latestUpdateState, transceiverUpdate)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n\n\tprivate updateCore<Core extends Transceiver<any>>(\n\t\tmutableState: MutableAtomToken<Core, Json.Serializable>,\n\t\tlatestUpdateState: RegularAtomToken<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst subscriptionKey = `tracker:${target.config.name}:${\n\t\t\tisChildStore(target) ? target.transactionMeta.update.key : `main`\n\t\t}:${mutableState.key}`\n\t\tsubscribeToState(\n\t\t\ttarget,\n\t\t\tlatestUpdateState,\n\t\t\tsubscriptionKey,\n\t\t\t({ newValue, oldValue }) => {\n\t\t\t\tconst timelineId = target.timelineTopics.getRelatedKey(\n\t\t\t\t\tlatestUpdateState.key,\n\t\t\t\t)\n\n\t\t\t\tif (timelineId) {\n\t\t\t\t\tconst timelineData = target.timelines.get(timelineId)\n\t\t\t\t\tif (timelineData?.timeTraveling) {\n\t\t\t\t\t\tconst unsubscribe = subscribeToTimeline(\n\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t{ key: timelineId, type: `timeline` },\n\t\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\tsetIntoStore(target, mutableState, (transceiver) => {\n\t\t\t\t\t\t\t\t\tif (update === `redo` && newValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.do(newValue)\n\t\t\t\t\t\t\t\t\t} else if (update === `undo` && oldValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.undo(oldValue)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn transceiver\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = target.on.operationClose.subscribe(\n\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\tconst mutable = getFromStore(target, mutableState)\n\t\t\t\t\t\tconst updateNumber =\n\t\t\t\t\t\t\tnewValue === null ? -1 : mutable.getUpdateNumber(newValue)\n\t\t\t\t\t\tconst eventOffset = updateNumber - mutable.cacheUpdateNumber\n\t\t\t\t\t\tif (newValue && eventOffset === 1) {\n\t\t\t\t\t\t\tsetIntoStore(\n\t\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t\tmutableState,\n\t\t\t\t\t\t\t\t(transceiver) => (transceiver.do(newValue), transceiver),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ttarget.logger.info(\n\t\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t\t`mutable_atom`,\n\t\t\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t\t\t`could not be updated. Expected update number ${\n\t\t\t\t\t\t\t\t\tmutable.cacheUpdateNumber + 1\n\t\t\t\t\t\t\t\t}, but got ${updateNumber}`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t},\n\t\t)\n\t}\n\n\tpublic mutableState: MutableAtomToken<Mutable, Json.Serializable>\n\tpublic latestUpdateState: RegularAtomToken<\n\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t>\n\n\tpublic [Symbol.dispose]!: () => void\n\n\tpublic constructor(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store,\n\t) {\n\t\tthis.mutableState = mutableState\n\t\tconst target = newest(store)\n\t\tthis.latestUpdateState = this.initializeState(mutableState, target)\n\t\tthis.observeCore(mutableState, this.latestUpdateState, target)\n\t\tthis.updateCore(mutableState, this.latestUpdateState, target)\n\t\ttarget.trackers.set(mutableState.key, this)\n\t\tthis[Symbol.dispose] = () => {\n\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\tthis.unsubscribeFromState()\n\t\t\ttarget.trackers.delete(mutableState.key)\n\t\t}\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJson } from \"atom.io/json\"\n\nimport type { MutableAtom } from \"..\"\nimport { resetInStore, setIntoStore } from \"..\"\nimport { newest } from \"../lineage\"\nimport { deposit, type Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtom<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(\n\tstore: Store,\n\toptions: MutableAtomOptions<T, J>,\n\tfamily: FamilyMetadata | undefined,\n): MutableAtomToken<T, J> {\n\tstore.logger.info(\n\t\t`🔨`,\n\t\t`atom`,\n\t\toptions.key,\n\t\t`creating in store \"${store.config.name}\"`,\n\t)\n\tconst target = newest(store)\n\tconst { key } = options\n\tconst existing = target.atoms.get(key)\n\tconst type = `mutable_atom`\n\tif (existing && existing.type === type) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttype,\n\t\t\tkey,\n\t\t\t`Tried to create atom, but it already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: MutableAtom<T, J> = {\n\t\t...options,\n\t\ttype,\n\t\tinstall: (s: Store) => {\n\t\t\ts.logger.info(`🛠️`, `atom`, key, `installing in store \"${s.config.name}\"`)\n\t\t\treturn createMutableAtom(s, options, family)\n\t\t},\n\t\tsubject,\n\t} as const\n\tif (family) {\n\t\tnewAtom.family = family\n\t}\n\ttarget.atoms.set(newAtom.key, newAtom)\n\tconst token = deposit(newAtom)\n\tif (options.effects) {\n\t\tlet effectIndex = 0\n\t\tconst cleanupFunctions: (() => void)[] = []\n\t\tfor (const effect of options.effects) {\n\t\t\tconst cleanup = effect({\n\t\t\t\tresetSelf: () => {\n\t\t\t\t\tresetInStore(store, token)\n\t\t\t\t},\n\t\t\t\tsetSelf: (next) => {\n\t\t\t\t\tsetIntoStore(store, token, next)\n\t\t\t\t},\n\t\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\t\tsubscribeToState(store, token, `effect[${effectIndex}]`, handle),\n\t\t\t})\n\t\t\tif (cleanup) {\n\t\t\t\tcleanupFunctions.push(cleanup)\n\t\t\t}\n\t\t\t++effectIndex\n\t\t}\n\t\tnewAtom.cleanup = () => {\n\t\t\tfor (const cleanup of cleanupFunctions) {\n\t\t\t\tcleanup()\n\t\t\t}\n\t\t}\n\t}\n\n\tnew Tracker(token, store)\n\tif (!family) {\n\t\tselectJson(token, options, store)\n\t}\n\n\treturn token\n}\n","import type { Canonical } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport type { MutableAtomFamily, RegularAtomFamily } from \"..\"\nimport { createRegularAtomFamily } from \"../families\"\nimport { type Store, withdraw } from \"../store\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport class FamilyTracker<\n\tCore extends Transceiver<any>,\n\tFamilyMemberKey extends Canonical,\n> {\n\tprivate trackers: Map<FamilyMemberKey, Tracker<Core>> = new Map()\n\n\tpublic readonly latestUpdateAtoms: RegularAtomFamily<\n\t\t(Core extends Transceiver<infer Signal> ? Signal : never) | null,\n\t\tFamilyMemberKey\n\t>\n\tpublic readonly mutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>\n\n\tpublic constructor(\n\t\tmutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>,\n\t\tstore: Store,\n\t) {\n\t\tconst updateAtoms = createRegularAtomFamily<\n\t\t\t(Core extends Transceiver<infer Signal> ? Signal : never) | null,\n\t\t\tFamilyMemberKey\n\t\t>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `*${mutableAtoms.key}`,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\t[`mutable`, `updates`],\n\t\t)\n\t\tthis.latestUpdateAtoms = withdraw(store, updateAtoms)\n\t\tthis.mutableAtoms = mutableAtoms\n\t\tthis.mutableAtoms.subject.subscribe(\n\t\t\t`store=${store.config.name}::tracker-atom-family`,\n\t\t\t(event) => {\n\t\t\t\tconst { type, token } = event\n\t\t\t\tif (token.family) {\n\t\t\t\t\tconst key = parseJson(token.family.subKey)\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase `state_creation`:\n\t\t\t\t\t\t\tthis.trackers.set(key, new Tracker<Core>(token, store))\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase `state_disposal`:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tconst tracker = this.trackers.get(key)\n\t\t\t\t\t\t\t\tif (tracker) {\n\t\t\t\t\t\t\t\t\ttracker[Symbol.dispose]()\n\t\t\t\t\t\t\t\t\tthis.trackers.delete(key)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tMutableAtomFamilyOptions,\n\tMutableAtomFamilyToken,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { selectJsonFamily, stringifyJson } from \"atom.io/json\"\n\nimport { type MutableAtomFamily, prettyPrintTokenType } from \"..\"\nimport { newest } from \"../lineage\"\nimport { createMutableAtom } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { FamilyTracker } from \"./tracker-family\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\toptions: MutableAtomFamilyOptions<T, J, K>,\n\tinternalRoles?: string[],\n): MutableAtomFamilyToken<T, J, K> {\n\tconst familyToken = {\n\t\tkey: options.key,\n\t\ttype: `mutable_atom_family`,\n\t} as const satisfies MutableAtomFamilyToken<T, J, K>\n\n\tconst existing = store.families.get(options.key)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\t`mutable_atom_family`,\n\t\t\toptions.key,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\n\tconst subject = new Subject<\n\t\tStateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>\n\t>()\n\n\tconst familyFunction = (key: K): MutableAtomToken<T, J> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\tconst fullKey = `${options.key}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst individualOptions: MutableAtomOptions<T, J> = {\n\t\t\tkey: fullKey,\n\t\t\tdefault: () => options.default(key),\n\t\t\ttoJson: options.toJson,\n\t\t\tfromJson: options.fromJson,\n\t\t\tmutable: true,\n\t\t}\n\t\tif (options.effects) {\n\t\t\tindividualOptions.effects = options.effects(key)\n\t\t}\n\n\t\tconst token = createMutableAtom(target, individualOptions, family)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst atomFamily = Object.assign(familyFunction, familyToken, {\n\t\tsubject,\n\t\tinstall: (s: Store) => createMutableAtomFamily(s, options),\n\t\ttoJson: options.toJson,\n\t\tfromJson: options.fromJson,\n\t\tinternalRoles,\n\t}) satisfies MutableAtomFamily<T, J, K>\n\n\tstore.families.set(options.key, atomFamily)\n\tselectJsonFamily(store, atomFamily, options)\n\tnew FamilyTracker(atomFamily, store)\n\treturn familyToken\n}\n","import type { MutableAtomFamilyToken } from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport type { WritablePureSelectorFamily } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonFamily = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Canonical,\n>(\n\tmutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>,\n\tstore: Store,\n): WritablePureSelectorFamily<SerializableCore, Key> => {\n\tconst target = newest(store)\n\tconst key = `${mutableAtomFamily.key}:JSON`\n\tconst jsonFamily: WritablePureSelectorFamily<SerializableCore, Key> =\n\t\ttarget.families.get(key) as WritablePureSelectorFamily<SerializableCore, Key>\n\treturn jsonFamily\n}\n","import type {\n\tMutableAtomToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { newest } from \"../lineage\"\nimport { type Store, withdraw } from \"../store\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonToken = <\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tstore: Store,\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): WritablePureSelectorToken<SerializableCore> => {\n\tif (mutableAtomToken.family) {\n\t\tconst target = newest(store)\n\t\tconst jsonFamilyKey = `${mutableAtomToken.family.key}:JSON`\n\t\tconst jsonFamilyToken: WritablePureSelectorFamilyToken<\n\t\t\tSerializableCore,\n\t\t\tstring\n\t\t> = {\n\t\t\tkey: jsonFamilyKey,\n\t\t\ttype: `writable_pure_selector_family`,\n\t\t}\n\t\tconst family = withdraw(target, jsonFamilyToken)\n\t\tconst subKey = JSON.parse(mutableAtomToken.family.subKey)\n\t\tconst jsonToken = findInStore(store, family, subKey)\n\t\treturn jsonToken\n\t}\n\tconst token: WritablePureSelectorToken<SerializableCore> = {\n\t\ttype: `writable_pure_selector`,\n\t\tkey: `${mutableAtomToken.key}:JSON`,\n\t}\n\treturn token\n}\n","import type { MutableAtomFamilyToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { AtomFamily } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport type { Signal, Transceiver } from \"./transceiver\"\n\nexport const getUpdateFamily = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends string,\n>(\n\tmutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>,\n\tstore: Store,\n): AtomFamily<Signal<Core>, Key> => {\n\tconst target = newest(store)\n\tconst key = `*${mutableAtomFamily.key}`\n\tconst updateFamily: AtomFamily<Signal<Core>, Key> = target.families.get(\n\t\tkey,\n\t) as AtomFamily<Signal<Core>, Key>\n\treturn updateFamily\n}\n","import type { MutableAtomToken, RegularAtomToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Signal, Transceiver } from \"./transceiver\"\n\nexport const getUpdateToken = <\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): RegularAtomToken<Signal<Core>> => {\n\tconst key = `*${mutableAtomToken.key}`\n\tconst updateToken: RegularAtomToken<Signal<Core>> = { type: `atom`, key }\n\tif (mutableAtomToken.family) {\n\t\tupdateToken.family = {\n\t\t\tkey: `*${mutableAtomToken.family.key}`,\n\t\t\tsubKey: mutableAtomToken.family.subKey,\n\t\t}\n\t}\n\treturn updateToken\n}\n","import type { Json } from \"atom.io/json\"\n\nexport interface Transceiver<S extends Json.Serializable> {\n\tdo: (update: S) => number | `OUT_OF_RANGE` | null\n\tundo: (update: S) => void\n\tsubscribe: (key: string, fn: (update: S) => void) => () => void\n\tcacheUpdateNumber: number\n\tgetUpdateNumber: (update: S) => number\n}\n\nexport function isTransceiver(\n\tvalue: unknown,\n): value is Transceiver<Json.Serializable> {\n\treturn (\n\t\ttypeof value === `object` &&\n\t\tvalue !== null &&\n\t\t`do` in value &&\n\t\t`undo` in value &&\n\t\t`subscribe` in value\n\t)\n}\n\nexport type TransceiverMode = `playback` | `record` | `transaction`\n\nexport type Signal<TVR extends Transceiver<any>> = TVR extends Transceiver<\n\tinfer S\n>\n\t? S\n\t: never\n\n/*\nA transceiver may also keep a list of updates that have been applied to it.\nThis is useful for undo/redo functionality, especially in the context of\nrevising history. It is a good idea to accept a cache limit in your \nconstructor, and overwrite old updates. Here's an example of how we \nmight set that up:\n\nmyTransceiver = Transceiver {\n\tcacheUpdateNumber: number = 27\n\tcacheIdx: number = 1\n\tcacheLimit: number = 3\n\tcache: Array<Update> = [\n\t\t26=add:\"x\"\n\t\t27=del:\"x\" (current)\n\t\t25=add:\"y\"\n\t]\n}\n\nCONFIRM/NO-OP\nUpdate `27=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 27, update = `del:\"x\"`]\t\n- updateOffset = updateNumber - cacheUpdateNumber // 0\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // 1\n- update === cache.get(eventIdx) // true\n- return null // 👍\n\nEXPECTED UPDATE\nUpdate `28=add:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 28, update = `add:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 1\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // true (we're ready to apply this update)\n- cacheIdx += eventOffset // 2\n- cacheIdx %= cacheLimit // 2\n- cache[cacheIdx] = update // cache = <{ 0 => add:\"x\" }>\n- return null // 👍\n\nUNEXPECTED UPDATE\nUpdate `29=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 29, update = `del:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 2\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // false (we're NOT ready to apply this update)\n- updateIdx := cacheIdx + updateOffset // 3\n- updateIdx %= cacheLimit // 0\n- cache[updateIdx] = update // cache = <{ 0 => del:\"x\" }> \n- expectedUpdateNumber = cacheUpdateNumber + 1 // 28\n- return expectedUpdateNumber // 🤨👂\n\nSUCCESSFUL ROLLBACK UPDATE\nUpdate `25=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 25, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -2\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // -1\n- eventIdx %= cacheLimit // 2\n- update === cache[eventIdx] // false (we're rolling back)\n- done := false\n- update := cache[cacheIdx] // update = `del:\"x\"`\n- undo(update) // myTransceiver.undo(`del:\"x\"`)\n- while (!done) {\n- \tcacheIdx -= 1 // 0, -1\n- \tcacheIdx %= cacheLimit // 0, 2\n- \tupdate = cache[cacheIdx] // update = `add:\"y\"`, `add:\"x\"`\n- \tundo(update) // myTransceiver.undo(`add:\"y\"`), myTransceiver.undo(`add:\"x\"`)\n- \tdone = cacheIdx === eventIdx // false, true\n- }\n- do(update) // myTransceiver.do(`add:\"z\"`)\n- return null // 👍\n\nUNSUCCESSFUL ROLLBACK UPDATE\nUpdate `24=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 24, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -3\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // 3 < 3 // false (we don't remember this update)\n- return `OUT_OF_RANGE` // 😵‍💫👂\n\n*/\n","import type {\n\tAtomToken,\n\tLogger,\n\tMoleculeCreation,\n\tMoleculeDisposal,\n\tSelectorToken,\n\tTimelineToken,\n\tTransactionToken,\n} from \"atom.io\"\nimport { AtomIOLogger } from \"atom.io\"\nimport type { Canonical, stringified } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tHeldSelectorFamily,\n\tMutableAtomFamily,\n\tPureSelectorFamily,\n\tReadonlySelector,\n\tRegularAtomFamily,\n\tWritableSelector,\n} from \"..\"\nimport { isReservedIntrospectionKey } from \"..\"\nimport type { Join } from \"../join\"\nimport { Junction } from \"../junction\"\nimport type { Lineage } from \"../lineage\"\nimport type { Molecule } from \"../molecule\"\nimport type { Tracker, Transceiver } from \"../mutable\"\nimport { getJsonToken, getUpdateToken } from \"../mutable\"\nimport type { OperationProgress } from \"../operation\"\nimport { StatefulSubject, Subject } from \"../subject\"\nimport type { Timeline } from \"../timeline\"\nimport type {\n\tTransaction,\n\tTransactionEpoch,\n\tTransactionProgress,\n} from \"../transaction\"\nimport { isRootStore } from \"../transaction\"\nimport type { Func } from \"../utility-types\"\nimport { CircularBuffer } from \"./circular-buffer\"\n\nexport class Store implements Lineage {\n\tpublic parent: Store | null = null\n\tpublic child: Store | null = null\n\n\tpublic valueMap: Map<string, any> = new Map()\n\tpublic defaults: Map<string, any> = new Map()\n\n\tpublic atoms: Map<string, Atom<any>> = new Map()\n\tpublic writableSelectors: Map<string, WritableSelector<any>> = new Map()\n\tpublic readonlySelectors: Map<string, ReadonlySelector<any>> = new Map()\n\n\tpublic atomsThatAreDefault: Set<string> = new Set()\n\tpublic selectorAtoms: Junction<`selectorKey`, string, `atomKey`, string> =\n\t\tnew Junction({\n\t\t\tbetween: [`selectorKey`, `atomKey`],\n\t\t\tcardinality: `n:n`,\n\t\t})\n\tpublic selectorGraph: Junction<\n\t\t`upstreamSelectorKey`,\n\t\tstring,\n\t\t`downstreamSelectorKey`,\n\t\tstring,\n\t\t{ source: string }\n\t> = new Junction(\n\t\t{\n\t\t\tbetween: [`upstreamSelectorKey`, `downstreamSelectorKey`],\n\t\t\tcardinality: `n:n`,\n\t\t},\n\t\t{\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t},\n\t)\n\tpublic trackers: Map<string, Tracker<Transceiver<any>>> = new Map()\n\tpublic families: Map<\n\t\tstring,\n\t\t| HeldSelectorFamily<any, any>\n\t\t| MutableAtomFamily<any, any, any>\n\t\t| PureSelectorFamily<any, any>\n\t\t| RegularAtomFamily<any, any>\n\t> = new Map()\n\tpublic joins: Map<string, Join<any, any, any, any, any, any>> = new Map()\n\n\tpublic transactions: Map<string, Transaction<Func>> = new Map()\n\tpublic transactionMeta: TransactionEpoch | TransactionProgress<Func> = {\n\t\tepoch: new Map<string, number>(),\n\t\tactionContinuities: new Junction({\n\t\t\tbetween: [`continuity`, `action`],\n\t\t\tcardinality: `1:n`,\n\t\t}),\n\t}\n\n\tpublic timelines: Map<string, Timeline<any>> = new Map()\n\tpublic timelineTopics: Junction<\n\t\t`timelineKey`,\n\t\tstring,\n\t\t`topicKey`,\n\t\tstring,\n\t\t{ topicType: `atom_family` | `atom` | `molecule_family` | `molecule` }\n\t> = new Junction({\n\t\tbetween: [`timelineKey`, `topicKey`],\n\t\tcardinality: `1:n`,\n\t})\n\n\tpublic disposalTraces: CircularBuffer<{ key: string; trace: string }> =\n\t\tnew CircularBuffer(100)\n\n\tpublic molecules: Map<string, Molecule<Canonical>> = new Map()\n\tpublic moleculeJoins: Junction<\n\t\t`moleculeKey`,\n\t\tstringified<Canonical>,\n\t\t`joinKey`,\n\t\tstring\n\t> = new Junction(\n\t\t{\n\t\t\tbetween: [`moleculeKey`, `joinKey`],\n\t\t\tcardinality: `n:n`,\n\t\t},\n\t\t{\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t},\n\t)\n\tpublic moleculeGraph: Junction<\n\t\t`upstreamMoleculeKey`,\n\t\tstringified<Canonical> | `root`,\n\t\t`downstreamMoleculeKey`,\n\t\tstringified<Canonical>,\n\t\t{ source: stringified<Canonical> }\n\t> = new Junction(\n\t\t{\n\t\t\tbetween: [`upstreamMoleculeKey`, `downstreamMoleculeKey`],\n\t\t\tcardinality: `n:n`,\n\t\t},\n\t\t{\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t},\n\t)\n\tpublic moleculeData: Junction<\n\t\t`moleculeKey`,\n\t\tstringified<Canonical>,\n\t\t`stateFamilyKey`,\n\t\tstring\n\t> = new Junction(\n\t\t{\n\t\t\tbetween: [`moleculeKey`, `stateFamilyKey`],\n\t\t\tcardinality: `n:n`,\n\t\t},\n\t\t{\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t},\n\t)\n\tpublic miscResources: Map<string, Disposable> = new Map()\n\n\tpublic on: StoreEventCarrier = {\n\t\tatomCreation: new Subject(),\n\t\tatomDisposal: new Subject(),\n\t\tselectorCreation: new Subject(),\n\t\tselectorDisposal: new Subject(),\n\t\ttimelineCreation: new Subject(),\n\t\ttransactionCreation: new Subject(),\n\t\ttransactionApplying: new StatefulSubject(null),\n\t\toperationClose: new Subject(),\n\t\tmoleculeCreation: new Subject(),\n\t\tmoleculeDisposal: new Subject(),\n\t}\n\tpublic operation: OperationProgress = { open: false }\n\n\tpublic config: {\n\t\tname: string\n\t\tlifespan: `ephemeral` | `immortal`\n\t} = {\n\t\tname: `IMPLICIT_STORE`,\n\t\tlifespan: `ephemeral`,\n\t}\n\n\tpublic loggers: AtomIOLogger[] = [\n\t\tnew AtomIOLogger(`warn`, (_, __, key) => !isReservedIntrospectionKey(key)),\n\t]\n\tpublic logger: Logger = {\n\t\terror: (...messages) => {\n\t\t\tfor (const logger of this.loggers) logger.error(...messages)\n\t\t},\n\t\tinfo: (...messages) => {\n\t\t\tfor (const logger of this.loggers) logger.info(...messages)\n\t\t},\n\t\twarn: (...messages) => {\n\t\t\tfor (const logger of this.loggers) logger.warn(...messages)\n\t\t},\n\t}\n\n\tpublic constructor(config: Store[`config`], store: Store | null = null) {\n\t\tthis.config = {\n\t\t\t...store?.config,\n\t\t\t...config,\n\t\t}\n\t\tif (store !== null) {\n\t\t\tthis.operation = { ...store?.operation }\n\t\t\tif (isRootStore(store)) {\n\t\t\t\tthis.transactionMeta = {\n\t\t\t\t\tepoch: new Map(store?.transactionMeta.epoch),\n\t\t\t\t\tactionContinuities: new Junction(\n\t\t\t\t\t\tstore?.transactionMeta.actionContinuities.toJSON(),\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const [, family] of store.families) {\n\t\t\t\tif (\n\t\t\t\t\tfamily.internalRoles?.includes(`mutable`) ||\n\t\t\t\t\tfamily.internalRoles?.includes(`join`)\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfamily.install(this)\n\t\t\t}\n\t\t\tconst mutableHelpers = new Set<string>()\n\t\t\tfor (const [, atom] of store.atoms) {\n\t\t\t\tif (mutableHelpers.has(atom.key)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tatom.install(this)\n\t\t\t\tif (atom.type === `mutable_atom`) {\n\t\t\t\t\tconst originalJsonToken = getJsonToken(store, atom)\n\t\t\t\t\tconst originalUpdateToken = getUpdateToken(atom)\n\t\t\t\t\tmutableHelpers.add(originalJsonToken.key)\n\t\t\t\t\tmutableHelpers.add(originalUpdateToken.key)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [, selector] of store.readonlySelectors) {\n\t\t\t\tselector.install(this)\n\t\t\t}\n\t\t\tfor (const [, selector] of store.writableSelectors) {\n\t\t\t\tif (mutableHelpers.has(selector.key)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tselector.install(this)\n\t\t\t}\n\t\t\tfor (const [, tx] of store.transactions) {\n\t\t\t\ttx.install(this)\n\t\t\t}\n\t\t\tfor (const [, timeline] of store.timelines) {\n\t\t\t\ttimeline.install(this)\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport type StoreEventCarrier = {\n\tatomCreation: Subject<AtomToken<unknown>>\n\tatomDisposal: Subject<AtomToken<unknown>>\n\tselectorCreation: Subject<SelectorToken<unknown>>\n\tselectorDisposal: Subject<SelectorToken<unknown>>\n\ttimelineCreation: Subject<TimelineToken<unknown>>\n\ttransactionCreation: Subject<TransactionToken<Func>>\n\ttransactionApplying: StatefulSubject<TransactionProgress<Func> | null>\n\toperationClose: Subject<OperationProgress>\n\tmoleculeCreation: Subject<MoleculeCreation>\n\tmoleculeDisposal: Subject<MoleculeDisposal>\n}\n\ndeclare global {\n\tvar ATOM_IO_IMPLICIT_STORE: Store | undefined\n}\n\nexport const IMPLICIT: { readonly STORE: Store } = {\n\tget STORE(): Store {\n\t\tglobalThis.ATOM_IO_IMPLICIT_STORE ??= new Store({\n\t\t\tname: `IMPLICIT_STORE`,\n\t\t\tlifespan: `ephemeral`,\n\t\t})\n\t\treturn globalThis.ATOM_IO_IMPLICIT_STORE\n\t},\n}\n\nexport const clearStore = (store: Store): void => {\n\tconst { config } = store\n\tfor (const disposable of store.miscResources.values()) {\n\t\tdisposable[Symbol.dispose]()\n\t}\n\tObject.assign(store, new Store(config))\n\tstore.config = config\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomIOToken,\n\tAtomToken,\n\tHeldSelectorFamilyToken,\n\tHeldSelectorToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tPureSelectorFamilyToken,\n\tPureSelectorToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyHeldSelectorFamilyToken,\n\tReadonlyHeldSelectorToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tReadonlySelectorFamilyToken,\n\tReadonlySelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableFamilyToken,\n\tWritableHeldSelectorFamilyToken,\n\tWritableHeldSelectorToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableSelectorFamilyToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tFunc,\n\tHeldSelector,\n\tHeldSelectorFamily,\n\tMutableAtom,\n\tMutableAtomFamily,\n\tPureSelector,\n\tPureSelectorFamily,\n\tReadableFamily,\n\tReadableState,\n\tReadonlyHeldSelector,\n\tReadonlyHeldSelectorFamily,\n\tReadonlyPureSelector,\n\tReadonlyPureSelectorFamily,\n\tReadonlySelector,\n\tReadonlySelectorFamily,\n\tRegularAtom,\n\tRegularAtomFamily,\n\tSelector,\n\tSelectorFamily,\n\tTransceiver,\n\tWritableFamily,\n\tWritableHeldSelector,\n\tWritableHeldSelectorFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableSelector,\n\tWritableSelectorFamily,\n\tWritableState,\n} from \"..\"\nimport { NotFoundError } from \"..\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Store } from \"./store\"\n\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T>,\n): RegularAtom<T>\nexport function withdraw<T extends Transceiver<any>>(\n\tstore: Store,\n\ttoken: MutableAtomToken<T, any>,\n): MutableAtom<T, any>\nexport function withdraw<T>(store: Store, token: AtomToken<T>): Atom<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritableHeldSelectorToken<T>,\n): WritableHeldSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadonlyHeldSelectorToken<T>,\n): ReadonlyHeldSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T>,\n): WritablePureSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T>,\n): ReadonlyPureSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadonlySelectorToken<T>,\n): ReadonlySelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritableSelectorToken<T>,\n): WritableSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: HeldSelectorToken<T>,\n): HeldSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: PureSelectorToken<T>,\n): PureSelector<T>\nexport function withdraw<T>(store: Store, token: SelectorToken<T>): Selector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritableToken<T>,\n): WritableState<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadableToken<T>,\n): ReadableState<T>\n\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K>,\n): RegularAtomFamily<T, K>\nexport function withdraw<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, J, K>,\n): MutableAtomFamily<T, J, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K>,\n): AtomFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlyHeldSelectorFamilyToken<T, K>,\n): ReadonlyHeldSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableHeldSelectorFamilyToken<T, K>,\n): WritableHeldSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n): ReadonlyPureSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n): WritablePureSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlySelectorFamilyToken<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableSelectorFamilyToken<T, K>,\n): WritableSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: HeldSelectorFamilyToken<T, K>,\n): HeldSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: PureSelectorFamilyToken<T, K>,\n): PureSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K>,\n): SelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n): ReadableFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n): WritableFamily<T, K>\n\nexport function withdraw<T extends Func>(\n\tstore: Store,\n\ttoken: TransactionToken<T>,\n): Transaction<T extends Func ? T : never>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: TimelineToken<T>,\n): Timeline<T extends TimelineManageable ? T : never>\n\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritableToken<T>,\n): WritableState<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadableToken<T>,\n): ReadableState<T>\n\nexport function withdraw(\n\tstore: Store,\n\ttoken: AtomIOToken,\n): AtomIOInternalResource\n\nexport function withdraw(\n\tstore: Store,\n\ttoken: AtomIOToken,\n): AtomIOInternalResource {\n\tlet withdrawn: AtomIOInternalResource | undefined\n\tlet target: Store | null = store\n\twhile (target !== null) {\n\t\tswitch (token.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\twithdrawn = target.atoms.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `writable_pure_selector`:\n\t\t\tcase `writable_held_selector`:\n\t\t\t\twithdrawn = target.writableSelectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `readonly_pure_selector`:\n\t\t\tcase `readonly_held_selector`:\n\t\t\t\twithdrawn = target.readonlySelectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\tcase `writable_pure_selector_family`:\n\t\t\tcase `readonly_pure_selector_family`:\n\t\t\tcase `writable_held_selector_family`:\n\t\t\tcase `readonly_held_selector_family`:\n\t\t\t\twithdrawn = target.families.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `timeline`:\n\t\t\t\twithdrawn = target.timelines.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `transaction`:\n\t\t\t\twithdrawn = target.transactions.get(token.key)\n\t\t\t\tbreak\n\t\t}\n\t\tif (withdrawn) {\n\t\t\treturn withdrawn\n\t\t}\n\t\ttarget = target.child\n\t}\n\tthrow new NotFoundError(token, store)\n}\n","import type {\n\tFamilyMetadata,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\n\nimport { type RegularAtom, resetInStore, setIntoStore } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\n\nexport function createRegularAtom<T>(\n\tstore: Store,\n\toptions: RegularAtomOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): RegularAtomToken<T> {\n\tconst type = `atom`\n\tconst { key } = options\n\tstore.logger.info(\n\t\t`🔨`,\n\t\t`atom`,\n\t\tkey,\n\t\t`creating in store \"${store.config.name}\"`,\n\t)\n\tconst target = newest(store)\n\tconst existing = target.atoms.get(key)\n\tif (existing && existing.type === type) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`atom`,\n\t\t\tkey,\n\t\t\t`Tried to create atom, but it already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: RegularAtom<T> = {\n\t\t...options,\n\t\ttype,\n\t\tinstall: (s: Store) => {\n\t\t\ts.logger.info(`🛠️`, type, key, `installing in store \"${s.config.name}\"`)\n\t\t\treturn createRegularAtom(s, options, family)\n\t\t},\n\t\tsubject,\n\t} as const\n\tif (family) {\n\t\tnewAtom.family = family\n\t}\n\t// let initialValue = def\n\t// if (def instanceof Function) {\n\t// \tinitialValue = def()\n\t// }\n\ttarget.atoms.set(key, newAtom)\n\t// cacheValue(target, key, initialValue, subject)\n\tconst token = deposit(newAtom)\n\tif (options.effects) {\n\t\tlet effectIndex = 0\n\t\tconst cleanupFunctions: (() => void)[] = []\n\t\tfor (const effect of options.effects) {\n\t\t\tconst cleanup = effect({\n\t\t\t\tresetSelf: () => {\n\t\t\t\t\tresetInStore(store, token)\n\t\t\t\t},\n\t\t\t\tsetSelf: (next) => {\n\t\t\t\t\tsetIntoStore(store, token, next)\n\t\t\t\t},\n\t\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\t\tsubscribeToState(store, token, `effect[${effectIndex}]`, handle),\n\t\t\t})\n\t\t\tif (cleanup) {\n\t\t\t\tcleanupFunctions.push(cleanup)\n\t\t\t}\n\t\t\t++effectIndex\n\t\t}\n\t\tnewAtom.cleanup = () => {\n\t\t\tfor (const cleanup of cleanupFunctions) {\n\t\t\t\tcleanup()\n\t\t\t}\n\t\t}\n\t}\n\treturn token\n}\n","import type {\n\tAtomToken,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport { createMutableAtom } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { createRegularAtom } from \"./create-regular-atom\"\n\nexport function createStandaloneAtom<T>(\n\tstore: Store,\n\toptions: RegularAtomOptions<T>,\n): RegularAtomToken<T>\n\nexport function createStandaloneAtom<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(store: Store, options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>\n\nexport function createStandaloneAtom<T>(\n\tstore: Store,\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n): AtomToken<T> {\n\tconst isMutable = `mutable` in options\n\n\tif (isMutable) {\n\t\tconst state = createMutableAtom(store, options, undefined)\n\t\tstore.on.atomCreation.next(state)\n\t\treturn state\n\t}\n\tconst state = createRegularAtom(store, options, undefined)\n\tstore.on.atomCreation.next(state)\n\treturn state\n}\n","import type { AtomDisposal, AtomToken } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { getUpdateToken, isChildStore, newest, withdraw } from \"..\"\n\nexport function disposeAtom(store: Store, atomToken: AtomToken<unknown>): void {\n\tconst target = newest(store)\n\tconst { key, family } = atomToken\n\tconst atom = withdraw(target, atomToken)\n\tif (!family) {\n\t\tstore.logger.error(`❌`, `atom`, key, `Standalone atoms cannot be disposed.`)\n\t} else {\n\t\tatom.cleanup?.()\n\t\tconst lastValue = store.valueMap.get(atom.key)\n\t\tconst atomFamily = withdraw(store, { key: family.key, type: `atom_family` })\n\n\t\tconst disposal: AtomDisposal<AtomToken<unknown>> = {\n\t\t\ttype: `state_disposal`,\n\t\t\tsubType: `atom`,\n\t\t\ttoken: atomToken,\n\t\t\tvalue: lastValue,\n\t\t}\n\n\t\tatomFamily.subject.next(disposal)\n\n\t\tconst isChild = isChildStore(target)\n\n\t\ttarget.atoms.delete(key)\n\t\ttarget.valueMap.delete(key)\n\t\ttarget.selectorAtoms.delete(key)\n\t\ttarget.atomsThatAreDefault.delete(key)\n\t\tstore.timelineTopics.delete(key)\n\n\t\tif (atomToken.type === `mutable_atom`) {\n\t\t\tconst updateToken = getUpdateToken(atomToken)\n\t\t\tdisposeAtom(store, updateToken)\n\t\t\tstore.trackers.delete(key)\n\t\t}\n\t\tstore.logger.info(`🔥`, `atom`, key, `deleted`)\n\t\tif (isChild && target.transactionMeta.phase === `building`) {\n\t\t\tconst mostRecentUpdate = target.transactionMeta.update.updates.at(-1)\n\t\t\tconst wasMoleculeDisposal = mostRecentUpdate?.type === `molecule_disposal`\n\t\t\tconst updateAlreadyCaptured =\n\t\t\t\twasMoleculeDisposal &&\n\t\t\t\tmostRecentUpdate.values.some(([k]) => k === atom.family?.key)\n\n\t\t\tif (!updateAlreadyCaptured) {\n\t\t\t\ttarget.transactionMeta.update.updates.push(disposal)\n\t\t\t}\n\t\t} else {\n\t\t\tstore.on.atomDisposal.next(atomToken)\n\t\t}\n\t}\n}\n","import type { AtomIOToken } from \"atom.io\"\n\nimport { newest } from \"./lineage\"\nimport { type Store, withdraw } from \"./store\"\nimport { isChildStore } from \"./transaction\"\n\n/**\n * @public\n * Install the given tokens into the target store\n * @param tokens - States, families, transactions, and timelines to install into the target store\n * @param target - The store to install the tokens into\n * @param source - The store to install the tokens from\n *\n */\nexport function installIntoStore(\n\ttokens: AtomIOToken[],\n\ttarget: Store,\n\tsource: Store,\n): void {\n\tconst sourceNewest = newest(source)\n\tif (isChildStore(sourceNewest)) {\n\t\tsource.logger.error(\n\t\t\t`❌`,\n\t\t\t`transaction`,\n\t\t\tsourceNewest.transactionMeta.update.key,\n\t\t\t`could not install the following tokens into store \"${target.config.name} from \"${source.config.name}\":`,\n\t\t\ttokens,\n\t\t\t`${sourceNewest.config.name} is undergoing a transaction.`,\n\t\t)\n\t\treturn\n\t}\n\tconst targetNewest = newest(target)\n\tif (isChildStore(targetNewest)) {\n\t\ttarget.logger.error(\n\t\t\t`❌`,\n\t\t\t`transaction`,\n\t\t\ttargetNewest.transactionMeta.update.key,\n\t\t\t`could not install the following tokens into store \"${target.config.name} from \"${source.config.name}\":`,\n\t\t\ttokens,\n\t\t\t`${targetNewest.config.name} is undergoing a transaction.`,\n\t\t)\n\t\treturn\n\t}\n\tfor (const token of tokens) {\n\t\tconst resource = withdraw(source, token)\n\t\tresource.install(target)\n\t}\n}\n","import type { JoinOptions, JoinToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { Join } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function createJoin<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object,\n>(\n\tstore: Store,\n\toptions: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,\n\tdefaultContent: Content | undefined,\n): JoinToken<ASide, AType, BSide, BType, Cardinality, Content> {\n\tstore.joins.set(options.key, new Join(options, defaultContent, store))\n\tconst token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content> = {\n\t\tkey: options.key,\n\t\ttype: `join`,\n\t\ta: options.between[0],\n\t\tb: options.between[1],\n\t\tcardinality: options.cardinality,\n\t}\n\treturn token\n}\n","import type {\n\tCompoundTypedKey,\n\tfindState,\n\tgetState,\n\tJoinOptions,\n\tMutableAtomFamilyToken,\n\tRead,\n\tReadonlyPureSelectorFamilyToken,\n\tRegularAtomFamilyToken,\n\tsetState,\n\tSetterToolkit,\n\tWrite,\n} from \"atom.io\"\nimport { Anarchy } from \"atom.io\"\nimport type { Canonical, Json, stringified } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\nimport type { SetRTXJson } from \"atom.io/transceivers/set-rtx\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport { capitalize } from \"../capitalize\"\nimport {\n\tcreateReadonlyPureSelectorFamily,\n\tcreateRegularAtomFamily,\n\tfindInStore,\n} from \"../families\"\nimport { getFromStore } from \"../get-state\"\nimport type {\n\tBaseExternalStoreConfiguration,\n\tExternalStoreConfiguration,\n} from \"../junction\"\nimport { Junction } from \"../junction\"\nimport type { Molecule } from \"../molecule\"\nimport { createMutableAtomFamily, getJsonFamily, getJsonToken } from \"../mutable\"\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\n\nexport type JoinStateFamilies<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object | null,\n> = Cardinality extends `1:1`\n\t? (Content extends Json.Object\n\t\t\t? {\n\t\t\t\t\treadonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t[AType, Content] | null,\n\t\t\t\t\t\tBType\n\t\t\t\t\t>\n\t\t\t\t} & {\n\t\t\t\t\treadonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t[BType, Content] | null,\n\t\t\t\t\t\tAType\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t: {}) & {\n\t\t\treadonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\tAType | null,\n\t\t\t\tBType\n\t\t\t>\n\t\t} & {\n\t\t\treadonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\tBType | null,\n\t\t\t\tAType\n\t\t\t>\n\t\t}\n\t: Cardinality extends `1:n`\n\t\t? (Content extends Json.Object\n\t\t\t\t? {\n\t\t\t\t\t\treadonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t\t[AType, Content] | null,\n\t\t\t\t\t\t\tBType\n\t\t\t\t\t\t>\n\t\t\t\t\t} & {\n\t\t\t\t\t\treadonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t\t[BType, Content][],\n\t\t\t\t\t\t\tAType\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t: {}) & {\n\t\t\t\treadonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\tAType | null,\n\t\t\t\t\tBType\n\t\t\t\t>\n\t\t\t} & {\n\t\t\t\treadonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\tBType[],\n\t\t\t\t\tAType\n\t\t\t\t>\n\t\t\t}\n\t\t: Cardinality extends `n:n`\n\t\t\t? (Content extends Json.Object\n\t\t\t\t\t? {\n\t\t\t\t\t\t\treadonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t\t\t[AType, Content][],\n\t\t\t\t\t\t\t\tBType\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t} & {\n\t\t\t\t\t\t\treadonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t\t\t[BType, Content][],\n\t\t\t\t\t\t\t\tAType\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}) & {\n\t\t\t\t\treadonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\tAType[],\n\t\t\t\t\t\tBType\n\t\t\t\t\t>\n\t\t\t\t} & {\n\t\t\t\t\treadonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\tBType[],\n\t\t\t\t\t\tAType\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t: never\n\nexport class Join<\n\tconst ASide extends string,\n\tconst AType extends string,\n\tconst BSide extends string,\n\tconst BType extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object | null = null,\n\tconst ContentKey extends CompoundTypedKey<\n\t\t`content`,\n\t\tASide,\n\t\tBSide\n\t> = CompoundTypedKey<`content`, ASide, BSide>,\n> {\n\tprivate toolkit: SetterToolkit\n\tpublic options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>\n\tpublic defaultContent: Content | undefined\n\tpublic molecules: Map<string, Molecule<any>> = new Map()\n\tpublic relations: Junction<ASide, AType, BSide, BType, Content>\n\tpublic states: JoinStateFamilies<\n\t\tASide,\n\t\tAType,\n\t\tBSide,\n\t\tBType,\n\t\tCardinality,\n\t\tContent\n\t>\n\tpublic core: {\n\t\trelatedKeysAtoms: MutableAtomFamilyToken<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n\tpublic transact(\n\t\ttoolkit: SetterToolkit,\n\t\trun: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void,\n\t): void {\n\t\tconst originalToolkit = this.toolkit\n\t\tthis.toolkit = toolkit\n\t\trun(this)\n\t\tthis.toolkit = originalToolkit\n\t}\n\n\tpublic store: Store\n\tpublic realm: Anarchy\n\n\tpublic [Symbol.dispose](): void {}\n\n\tpublic constructor(\n\t\toptions: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,\n\t\tdefaultContent: Content | undefined,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) {\n\t\ttype AnyKey = AType & BType\n\n\t\tthis.store = store\n\t\tthis.realm = new Anarchy(store)\n\t\tthis.options = options\n\t\tthis.defaultContent = defaultContent\n\n\t\tthis.store.miscResources.set(`join:${options.key}`, this)\n\n\t\tthis.realm.allocate(`root`, options.key)\n\n\t\tthis.toolkit = {\n\t\t\tget: ((...ps: Parameters<typeof getState>) =>\n\t\t\t\tgetFromStore(store, ...ps)) as typeof getState,\n\t\t\tset: ((...ps: Parameters<typeof setState>) => {\n\t\t\t\tsetIntoStore(store, ...ps)\n\t\t\t}) as typeof setState,\n\t\t\tfind: ((...ps: Parameters<typeof findState>) =>\n\t\t\t\tfindInStore(store, ...ps)) as typeof findState,\n\t\t\tjson: (token) => getJsonToken(store, token),\n\t\t}\n\n\t\tconst aSide: ASide = options.between[0]\n\t\tconst bSide: BSide = options.between[1]\n\t\tconst relatedKeysAtoms = createMutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tdefault: () => new SetRTX(),\n\t\t\t\tmutable: true,\n\t\t\t\tfromJson: (json) => SetRTX.fromJSON(json),\n\t\t\t\ttoJson: (set) => set.toJSON(),\n\t\t\t},\n\t\t\t[`join`, `relations`],\n\t\t)\n\t\tthis.core = { relatedKeysAtoms }\n\t\tconst getRelatedKeys: Read<\n\t\t\t(key: string) => SetRTX<AType> | SetRTX<BType>\n\t\t> = ({ get }, key) => get(relatedKeysAtoms, key) as any\n\t\tconst addRelation: Write<(a: string, b: string) => void> = (\n\t\t\t{ set },\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tif (!this.store.molecules.has(stringifyJson(a))) {\n\t\t\t\tthis.realm.allocate(options.key, a)\n\t\t\t}\n\t\t\tset(relatedKeysAtoms, a, (aKeys) => aKeys.add(b))\n\t\t\tset(relatedKeysAtoms, b, (bKeys) => bKeys.add(a))\n\t\t}\n\t\tconst deleteRelation: Write<(a: string, b: string) => void> = (\n\t\t\t{ set },\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tset(relatedKeysAtoms, a, (aKeys) => {\n\t\t\t\taKeys.delete(b)\n\t\t\t\treturn aKeys\n\t\t\t})\n\t\t\tset(relatedKeysAtoms, b, (bKeys) => {\n\t\t\t\tbKeys.delete(a)\n\t\t\t\treturn bKeys\n\t\t\t})\n\t\t}\n\t\tconst replaceRelationsSafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (toolkit, a, newRelationsOfA) => {\n\t\t\tconst { find, get, set } = toolkit\n\t\t\tconst relationsOfAState = find(relatedKeysAtoms, a)\n\t\t\tconst currentRelationsOfA = get(relationsOfAState)\n\t\t\tfor (const currentRelationB of currentRelationsOfA) {\n\t\t\t\tconst remainsRelated = newRelationsOfA.includes(currentRelationB)\n\t\t\t\tif (remainsRelated) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tset(relatedKeysAtoms, currentRelationB, (relationsOfB) => {\n\t\t\t\t\trelationsOfB.delete(a)\n\t\t\t\t\treturn relationsOfB\n\t\t\t\t})\n\t\t\t}\n\t\t\tset(relationsOfAState, (relationsOfA) => {\n\t\t\t\trelationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\t\tnextRelationsOfA.clear()\n\t\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\t\tconst relationsOfB = getRelatedKeys(toolkit, newRelationB)\n\t\t\t\t\t\tconst newRelationBIsAlreadyRelated = relationsOfB.has(a as AnyKey)\n\t\t\t\t\t\tif (this.relations.cardinality === `1:n`) {\n\t\t\t\t\t\t\tconst previousOwnersToDispose: string[] = []\n\t\t\t\t\t\t\tfor (const previousOwner of relationsOfB) {\n\t\t\t\t\t\t\t\tif (previousOwner === a) {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst previousOwnerRelations = getRelatedKeys(\n\t\t\t\t\t\t\t\t\ttoolkit,\n\t\t\t\t\t\t\t\t\tpreviousOwner,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tpreviousOwnerRelations.delete(newRelationB as AnyKey)\n\t\t\t\t\t\t\t\tif (previousOwnerRelations.size === 0) {\n\t\t\t\t\t\t\t\t\tpreviousOwnersToDispose.push(previousOwner)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!newRelationBIsAlreadyRelated && relationsOfB.size > 0) {\n\t\t\t\t\t\t\t\trelationsOfB.clear()\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor (const previousOwner of previousOwnersToDispose) {\n\t\t\t\t\t\t\t\tconst sorted = [newRelationB, previousOwner].sort()\n\t\t\t\t\t\t\t\tconst compositeKey = `\"${sorted[0]}:${sorted[1]}\"`\n\t\t\t\t\t\t\t\tthis.molecules.delete(compositeKey)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!newRelationBIsAlreadyRelated) {\n\t\t\t\t\t\t\trelationsOfB.add(a as AnyKey)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnextRelationsOfA.add(newRelationB)\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t})\n\t\t\t\treturn relationsOfA\n\t\t\t})\n\t\t}\n\t\tconst replaceRelationsUnsafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (toolkit, a, newRelationsOfA) => {\n\t\t\tconst { set } = toolkit\n\t\t\tset(relatedKeysAtoms, a, (relationsOfA) => {\n\t\t\t\trelationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\t\tnextRelationsOfA.add(newRelationB)\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t})\n\t\t\t\treturn relationsOfA\n\t\t\t})\n\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\tset(relatedKeysAtoms, newRelationB, (newRelationsB) => {\n\t\t\t\t\tnewRelationsB.add(a)\n\t\t\t\t\treturn newRelationsB\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t\tconst has: Read<(a: string, b?: string) => boolean> = (toolkit, a, b) => {\n\t\t\tconst aKeys = getRelatedKeys(toolkit, a)\n\t\t\treturn b ? aKeys.has(b as AnyKey) : aKeys.size > 0\n\t\t}\n\t\tconst baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\t\tgetRelatedKeys: (key) => getRelatedKeys(this.toolkit, key),\n\t\t\taddRelation: (a, b) => {\n\t\t\t\tthis.store.moleculeJoins.set(\n\t\t\t\t\ta as stringified<Canonical> /* 💥 RECONCILE */,\n\t\t\t\t\toptions.key,\n\t\t\t\t)\n\t\t\t\tthis.store.moleculeJoins.set(\n\t\t\t\t\tb as stringified<Canonical> /* 💥 RECONCILE */,\n\t\t\t\t\toptions.key,\n\t\t\t\t)\n\t\t\t\taddRelation(this.toolkit, a, b)\n\t\t\t},\n\t\t\tdeleteRelation: (a, b) => {\n\t\t\t\tdeleteRelation(this.toolkit, a, b)\n\t\t\t},\n\t\t\treplaceRelationsSafely: (a, bs) => {\n\t\t\t\treplaceRelationsSafely(this.toolkit, a, bs)\n\t\t\t},\n\t\t\treplaceRelationsUnsafely: (a, bs) => {\n\t\t\t\treplaceRelationsUnsafely(this.toolkit, a, bs)\n\t\t\t},\n\t\t\thas: (a, b) => has(this.toolkit, a, b),\n\t\t}\n\t\tlet externalStore: ExternalStoreConfiguration<Content>\n\t\tlet contentAtoms: RegularAtomFamilyToken<Content, string>\n\n\t\tif (defaultContent) {\n\t\t\tcontentAtoms = createRegularAtomFamily<Content, ContentKey>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/content`,\n\t\t\t\t\tdefault: defaultContent,\n\t\t\t\t},\n\t\t\t\t[`join`, `content`],\n\t\t\t)\n\n\t\t\tconst getContent: Read<(key: string) => Content | null> = ({ get }, key) =>\n\t\t\t\tget(contentAtoms, key)\n\t\t\tconst setContent: Write<(key: string, content: Content) => void> = (\n\t\t\t\t{ set },\n\t\t\t\tkey,\n\t\t\t\tcontent,\n\t\t\t) => {\n\t\t\t\tset(contentAtoms, key, content)\n\t\t\t}\n\n\t\t\tconst externalStoreWithContentConfiguration = {\n\t\t\t\tgetContent: (contentKey: ContentKey) => {\n\t\t\t\t\tconst content = getContent(this.toolkit, contentKey)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t\tsetContent: (contentKey: ContentKey, content: Content) => {\n\t\t\t\t\tsetContent(this.toolkit, contentKey, content)\n\t\t\t\t},\n\t\t\t\tdeleteContent: (contentKey: ContentKey) => {\n\t\t\t\t\tthis.realm.deallocate(contentKey)\n\t\t\t\t},\n\t\t\t}\n\t\t\texternalStore = Object.assign(\n\t\t\t\tbaseExternalStoreConfiguration,\n\t\t\t\texternalStoreWithContentConfiguration,\n\t\t\t) as ExternalStoreConfiguration<Content>\n\t\t} else {\n\t\t\texternalStore =\n\t\t\t\tbaseExternalStoreConfiguration as ExternalStoreConfiguration<Content>\n\t\t}\n\t\tconst relations = new Junction<ASide, AType, BSide, BType, Content>(\n\t\t\toptions as any,\n\t\t\t{\n\t\t\t\texternalStore,\n\t\t\t\tisAType: options.isAType,\n\t\t\t\tisBType: options.isBType,\n\t\t\t\tmakeContentKey: (...args) => {\n\t\t\t\t\tconst [a, b] = args\n\t\t\t\t\tconst sorted = args.sort()\n\t\t\t\t\tconst compositeKey = `${sorted[0]}:${sorted[1]}`\n\t\t\t\t\tconst aMolecule = store.molecules.get(stringifyJson(a))\n\t\t\t\t\tconst bMolecule = store.molecules.get(stringifyJson(b))\n\t\t\t\t\tif (!aMolecule) {\n\t\t\t\t\t\tthis.realm.allocate(options.key, a)\n\t\t\t\t\t}\n\t\t\t\t\tif (!bMolecule) {\n\t\t\t\t\t\tthis.realm.allocate(options.key, b)\n\t\t\t\t\t}\n\t\t\t\t\tthis.realm.allocate(a, compositeKey, `all`)\n\t\t\t\t\tthis.realm.claim(b, compositeKey)\n\t\t\t\t\tthis.store.moleculeJoins.set(compositeKey, options.key)\n\t\t\t\t\treturn compositeKey\n\t\t\t\t},\n\t\t\t},\n\t\t)\n\n\t\tconst createSingleKeySelectorFamily = () =>\n\t\t\tcreateReadonlyPureSelectorFamily<string | null, string>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedKey`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(relatedKeysAtoms, key)\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\treturn relatedKey\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t[`join`, `keys`],\n\t\t\t)\n\t\tconst getMultipleKeySelectorFamily = () => {\n\t\t\treturn createReadonlyPureSelectorFamily<string[], string>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedKeys`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(relatedKeysAtoms, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily, key)\n\t\t\t\t\t\t\treturn json.members\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t[`join`, `keys`],\n\t\t\t)\n\t\t}\n\t\tconst createSingleEntrySelectorFamily = () =>\n\t\t\tcreateReadonlyPureSelectorFamily<[string, Content] | null, string>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedEntry`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(x) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(relatedKeysAtoms, x)\n\t\t\t\t\t\t\tfor (const y of relatedKeys) {\n\t\t\t\t\t\t\t\tlet a = relations.isAType?.(x) ? x : undefined\n\t\t\t\t\t\t\t\tlet b = a === undefined ? (x as BType) : undefined\n\t\t\t\t\t\t\t\ta ??= y as AType\n\t\t\t\t\t\t\t\tb ??= y as BType\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(a, b)\n\t\t\t\t\t\t\t\tconst content = get(contentAtoms, contentKey)\n\t\t\t\t\t\t\t\treturn [y, content]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t[`join`, `entries`],\n\t\t\t)\n\t\tconst getMultipleEntrySelectorFamily = () =>\n\t\t\tcreateReadonlyPureSelectorFamily<[string, Content][], string>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedEntries`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(x) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(relatedKeysAtoms, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily, x)\n\t\t\t\t\t\t\treturn json.members.map((y) => {\n\t\t\t\t\t\t\t\tlet a = relations.isAType?.(x) ? x : undefined\n\t\t\t\t\t\t\t\tlet b = a === undefined ? (x as BType) : undefined\n\t\t\t\t\t\t\t\ta ??= y as AType\n\t\t\t\t\t\t\t\tb ??= y as BType\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(a, b)\n\t\t\t\t\t\t\t\tconst content = get(contentAtoms, contentKey)\n\t\t\t\t\t\t\t\treturn [y, content]\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t[`join`, `entries`],\n\t\t\t)\n\n\t\tswitch (options.cardinality) {\n\t\t\tcase `1:1`: {\n\t\t\t\tconst singleRelatedKeySelectors = createSingleKeySelectorFamily()\n\t\t\t\tconst stateKeyA = `${aSide}KeyOf${capitalize(bSide)}` as const\n\t\t\t\tconst stateKeyB = `${bSide}KeyOf${capitalize(aSide)}` as const\n\t\t\t\tconst baseStates = {\n\t\t\t\t\t[stateKeyA]: singleRelatedKeySelectors,\n\t\t\t\t\t[stateKeyB]: singleRelatedKeySelectors,\n\t\t\t\t} as JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\t\tlet states: JoinStateFamilies<\n\t\t\t\t\tASide,\n\t\t\t\t\tAType,\n\t\t\t\t\tBSide,\n\t\t\t\t\tBType,\n\t\t\t\t\tCardinality,\n\t\t\t\t\tContent\n\t\t\t\t>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst singleEntrySelectors = createSingleEntrySelectorFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${bSide}EntryOf${capitalize(aSide)}` as const\n\t\t\t\t\tconst contentStates = {\n\t\t\t\t\t\t[entriesStateKeyA]: singleEntrySelectors,\n\t\t\t\t\t\t[entriesStateKeyB]: singleEntrySelectors,\n\t\t\t\t\t}\n\t\t\t\t\tstates = Object.assign(baseStates, contentStates)\n\t\t\t\t} else {\n\t\t\t\t\tstates = baseStates\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.states = states\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst singleRelatedKeySelectors = createSingleKeySelectorFamily()\n\t\t\t\tconst multipleRelatedKeysSelectors = getMultipleKeySelectorFamily()\n\t\t\t\tconst stateKeyA = `${aSide}KeyOf${capitalize(bSide)}` as const\n\t\t\t\tconst stateKeyB = `${bSide}KeysOf${capitalize(aSide)}` as const\n\t\t\t\tconst baseStates = {\n\t\t\t\t\t[stateKeyA]: singleRelatedKeySelectors,\n\t\t\t\t\t[stateKeyB]: multipleRelatedKeysSelectors,\n\t\t\t\t} as JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\t\tlet states: JoinStateFamilies<\n\t\t\t\t\tASide,\n\t\t\t\t\tAType,\n\t\t\t\t\tBSide,\n\t\t\t\t\tBType,\n\t\t\t\t\tCardinality,\n\t\t\t\t\tContent\n\t\t\t\t>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst singleRelatedEntrySelectors = createSingleEntrySelectorFamily()\n\t\t\t\t\tconst multipleRelatedEntriesSelectors =\n\t\t\t\t\t\tgetMultipleEntrySelectorFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${bSide}EntriesOf${capitalize(\n\t\t\t\t\t\taSide,\n\t\t\t\t\t)}` as const\n\t\t\t\t\tconst contentStates = {\n\t\t\t\t\t\t[entriesStateKeyA]: singleRelatedEntrySelectors,\n\t\t\t\t\t\t[entriesStateKeyB]: multipleRelatedEntriesSelectors,\n\t\t\t\t\t}\n\t\t\t\t\tstates = Object.assign(baseStates, contentStates)\n\t\t\t\t} else {\n\t\t\t\t\tstates = baseStates\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.states = states\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `n:n`: {\n\t\t\t\tconst multipleRelatedKeysSelectors = getMultipleKeySelectorFamily()\n\t\t\t\tconst stateKeyA = `${aSide}KeysOf${capitalize(bSide)}` as const\n\t\t\t\tconst stateKeyB = `${bSide}KeysOf${capitalize(aSide)}` as const\n\t\t\t\tconst baseStates = {\n\t\t\t\t\t[stateKeyA]: multipleRelatedKeysSelectors,\n\t\t\t\t\t[stateKeyB]: multipleRelatedKeysSelectors,\n\t\t\t\t} as JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\t\tlet states: JoinStateFamilies<\n\t\t\t\t\tASide,\n\t\t\t\t\tAType,\n\t\t\t\t\tBSide,\n\t\t\t\t\tBType,\n\t\t\t\t\tCardinality,\n\t\t\t\t\tContent\n\t\t\t\t>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst multipleRelatedEntriesSelectors =\n\t\t\t\t\t\tgetMultipleEntrySelectorFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${aSide}EntriesOf${capitalize(\n\t\t\t\t\t\tbSide,\n\t\t\t\t\t)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${bSide}EntriesOf${capitalize(\n\t\t\t\t\t\taSide,\n\t\t\t\t\t)}` as const\n\t\t\t\t\tconst contentStates = {\n\t\t\t\t\t\t[entriesStateKeyA]: multipleRelatedEntriesSelectors,\n\t\t\t\t\t\t[entriesStateKeyB]: multipleRelatedEntriesSelectors,\n\t\t\t\t\t}\n\t\t\t\t\tstates = Object.assign(baseStates, contentStates)\n\t\t\t\t} else {\n\t\t\t\t\tstates = baseStates\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.states = states\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { JoinToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { IMPLICIT, type Store } from \"../store\"\nimport { Join } from \"./join-internal\"\n\nexport function getJoin<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object | null,\n>(\n\ttoken: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,\n\tstore: Store,\n): Join<ASide, AType, BSide, BType, Cardinality, Content> {\n\tlet myJoin = store.joins.get(token.key)\n\tif (myJoin === undefined) {\n\t\tconst rootJoinMap = IMPLICIT.STORE.joins\n\t\tconst rootJoin = rootJoinMap.get(token.key)\n\t\tif (rootJoin === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`Join \"${token.key}\" not found in store \"${store.config.name}\"`,\n\t\t\t)\n\t\t}\n\t\tmyJoin = new Join(rootJoin.options, rootJoin.defaultContent, store)\n\t\tstore.joins.set(token.key, myJoin)\n\t}\n\treturn myJoin\n}\n","import type { JoinToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Junction } from \"../junction\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { isChildStore } from \"../transaction\"\nimport { getJoin } from \"./get-join\"\n\nexport function editRelationsInStore<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object | null,\n>(\n\ttoken: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,\n\tchange: (relations: Junction<ASide, AType, BSide, BType, Content>) => void,\n\tstore: Store,\n): void {\n\tconst myJoin = getJoin(token, store)\n\tconst target = newest(store)\n\tif (isChildStore(target)) {\n\t\tconst { toolkit } = target.transactionMeta\n\t\tmyJoin.transact(toolkit, ({ relations }) => {\n\t\t\tchange(relations)\n\t\t})\n\t} else {\n\t\tchange(myJoin.relations)\n\t}\n}\n","import type { JoinStates, JoinToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { capitalize } from \"../capitalize\"\nimport { findInStore } from \"../families\"\nimport type { Store } from \"../store\"\nimport { getJoin } from \"./get-join\"\n\nexport function findRelationsInStore<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object | null,\n>(\n\ttoken: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,\n\tkey: AType | BType,\n\tstore: Store,\n): JoinStates<ASide, AType, BSide, BType, Cardinality, Content> {\n\tconst myJoin = getJoin(token, store)\n\tlet relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>\n\tswitch (token.cardinality satisfies `1:1` | `1:n` | `n:n`) {\n\t\tcase `1:1`: {\n\t\t\tconst keyAB = `${token.a}KeyOf${capitalize(token.b)}`\n\t\t\tconst keyBA = `${token.b}KeyOf${capitalize(token.a)}`\n\t\t\trelations = {\n\t\t\t\tget [keyAB]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyAB = myJoin.states[keyAB as any]\n\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t\tget [keyBA]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyBA = myJoin.states[keyBA as any]\n\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\tconst entryAB = `${token.a}EntryOf${capitalize(token.b)}`\n\t\t\tif (entryAB in myJoin.states) {\n\t\t\t\tconst entryBA = `${token.b}EntryOf${capitalize(token.a)}`\n\t\t\t\tObject.assign(relations, {\n\t\t\t\t\tget [entryAB]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyAB = myJoin.states[entryAB as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t\tget [entryBA]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyBA = myJoin.states[entryBA as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase `1:n`: {\n\t\t\tconst keyAB = `${token.a}KeyOf${capitalize(token.b)}`\n\t\t\tconst keysBA = `${token.b}KeysOf${capitalize(token.a)}`\n\t\t\trelations = {\n\t\t\t\tget [keyAB]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyAB = myJoin.states[keyAB as any]\n\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t\tget [keysBA]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyBA = myJoin.states[keysBA as any]\n\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\tconst entryAB = `${token.a}EntryOf${capitalize(token.b)}`\n\t\t\tif (entryAB in myJoin.states) {\n\t\t\t\tconst entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`\n\t\t\t\tObject.assign(relations, {\n\t\t\t\t\tget [entryAB]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyAB = myJoin.states[entryAB as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t\tget [entriesBA]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyBA = myJoin.states[entriesBA as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase `n:n`: {\n\t\t\tconst keysAB = `${token.a}KeysOf${capitalize(token.b)}`\n\t\t\tconst keysBA = `${token.b}KeysOf${capitalize(token.a)}`\n\t\t\trelations = {\n\t\t\t\tget [keysAB]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyAB = myJoin.states[keysAB as any]\n\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t\tget [keysBA]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyBA = myJoin.states[keysBA as any]\n\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\tconst entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`\n\t\t\tif (entriesAB in myJoin.states) {\n\t\t\t\tconst entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`\n\t\t\t\tObject.assign(relations, {\n\t\t\t\t\tget [entriesAB]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyAB = myJoin.states[entriesAB as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t\tget [entriesBA]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyBA = myJoin.states[entriesBA as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\treturn relations\n}\n","import type { JoinToken, MutableAtomFamilyToken } from \"atom.io\"\nimport type { SetRTX, SetRTXJson } from \"atom.io/transceivers/set-rtx\"\n\nimport type { Store } from \"../store\"\nimport { getJoin } from \"./get-join\"\n\nexport function getInternalRelationsFromStore(\n\ttoken: JoinToken<any, any, any, any, any, any>,\n\tstore: Store,\n): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {\n\tconst myJoin = getJoin(token, store)\n\tconst family = myJoin.core.relatedKeysAtoms\n\treturn family\n}\n","export type ReservedIntrospectionKey = `🔍 ${string}`\n\nexport function isReservedIntrospectionKey(\n\tvalue: string,\n): value is ReservedIntrospectionKey {\n\treturn value.startsWith(`🔍 `)\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tFamilyMetadata,\n\tMoleculeCreation,\n\tMoleculeDisposal,\n\tReadableToken,\n\tStateCreation,\n\tStateDisposal,\n\tStateUpdate,\n\tTimelineManageable,\n\tTimelineOptions,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTokenType,\n\tTransactionToken,\n\tTransactionUpdate,\n\tTransactionUpdateContent,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { getUpdateToken } from \"../mutable\"\nimport { type Store, withdraw } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { isChildStore } from \"../transaction\"\nimport type { Flat, Func } from \"../utility-types\"\n\nexport type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> = Flat<\n\tStateUpdate<TokenType<ManagedAtom>> & {\n\t\tkey: string\n\t\ttype: `atom_update`\n\t\ttimestamp: number\n\t\tfamily?: FamilyMetadata\n\t}\n>\nexport type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\ttype: `selector_update`\n\ttimestamp: number\n\tatomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[]\n}\nexport type TimelineTransactionUpdate = Flat<\n\tTransactionUpdate<Func> & {\n\t\tkey: string\n\t\ttype: `transaction_update`\n\t\ttimestamp: number\n\t}\n>\nexport type TimelineStateCreation<T extends ReadableToken<any>> = Flat<\n\tStateCreation<T> & { timestamp: number }\n>\nexport type TimelineStateDisposal<T extends ReadableToken<any>> = Flat<\n\tStateDisposal<T> & { timestamp: number }\n>\nexport type TimelineMoleculeCreation = Flat<\n\tMoleculeCreation & { timestamp: number }\n>\nexport type TimelineMoleculeDisposal = Flat<\n\tMoleculeDisposal & { timestamp: number }\n>\n\nexport type Timeline<ManagedAtom extends TimelineManageable> = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<ManagedAtom>,\n\t) => boolean\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineUpdate<ManagedAtom>[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: Store) => void\n\tsubject: Subject<TimelineUpdate<ManagedAtom> | `redo` | `undo`>\n\tsubscriptions: Map<string, () => void>\n}\n\nexport function createTimeline<ManagedAtom extends TimelineManageable>(\n\tstore: Store,\n\toptions: TimelineOptions<ManagedAtom>,\n\tdata?: Timeline<ManagedAtom>,\n): TimelineToken<ManagedAtom> {\n\tconst tl: Timeline<ManagedAtom> = {\n\t\ttype: `timeline`,\n\t\tkey: options.key,\n\t\tat: 0,\n\n\t\ttimeTraveling: null,\n\t\tselectorTime: null,\n\t\ttransactionKey: null,\n\t\t...data,\n\t\thistory: data?.history.map((update) => ({ ...update })) ?? [],\n\t\tinstall: (s) => createTimeline(s, options, tl),\n\t\tsubject: new Subject(),\n\t\tsubscriptions: new Map(),\n\t}\n\tif (options.shouldCapture) {\n\t\ttl.shouldCapture = options.shouldCapture\n\t}\n\tconst timelineKey = options.key\n\tconst target = newest(store)\n\tfor (const initialTopic of options.scope) {\n\t\tswitch (initialTopic.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\t{\n\t\t\t\t\tconst atomToken: AtomToken<ManagedAtom> = initialTopic\n\t\t\t\t\tconst atomKey = atomToken.key\n\t\t\t\t\tlet existingTimelineKey = target.timelineTopics.getRelatedKey(atomKey)\n\t\t\t\t\tif (`family` in atomToken) {\n\t\t\t\t\t\tconst familyKey = atomToken.family.key\n\t\t\t\t\t\texistingTimelineKey = target.timelineTopics.getRelatedKey(familyKey)\n\t\t\t\t\t\tif (existingTimelineKey) {\n\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t\t\t`Failed to add atom \"${atomKey}\" because its family \"${familyKey}\" already belongs to timeline \"${existingTimelineKey}\"`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (existingTimelineKey) {\n\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t\t`Failed to add atom \"${atomKey}\" because it already belongs to timeline \"${existingTimelineKey}\"`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\taddAtomToTimeline(store, atomToken, tl)\n\t\t\t\t}\n\t\t\t\tbreak\n\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\t\t{\n\t\t\t\t\tconst familyToken: AtomFamilyToken<any, any> = initialTopic\n\t\t\t\t\tconst familyKey = familyToken.key\n\t\t\t\t\tconst existingTimelineKey =\n\t\t\t\t\t\ttarget.timelineTopics.getRelatedKey(familyKey)\n\t\t\t\t\tif (existingTimelineKey) {\n\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t\t`Failed to add atom family \"${familyKey}\" because it already belongs to timeline \"${existingTimelineKey}\"`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\taddAtomFamilyToTimeline(store, familyToken, tl)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\tstore.timelines.set(options.key, tl)\n\tconst token: TimelineToken<ManagedAtom> = {\n\t\tkey: timelineKey,\n\t\ttype: `timeline`,\n\t}\n\tstore.on.timelineCreation.next(token)\n\treturn token\n}\n\nfunction addAtomToTimeline(\n\tstore: Store,\n\tatomToken: AtomToken<any>,\n\ttl: Timeline<any>,\n): void {\n\tlet maybeAtom = withdraw(store, atomToken)\n\tif (maybeAtom.type === `mutable_atom`) {\n\t\tconst updateToken = getUpdateToken(maybeAtom)\n\t\tmaybeAtom = withdraw(store, updateToken)\n\t}\n\tconst atom = maybeAtom\n\tstore.timelineTopics.set(\n\t\t{ topicKey: atom.key, timelineKey: tl.key },\n\t\t{ topicType: `atom` },\n\t)\n\n\ttl.subscriptions.set(\n\t\tatom.key,\n\t\tatom.subject.subscribe(\n\t\t\t`timeline`,\n\t\t\tfunction timelineCapturesAtomUpdate(update) {\n\t\t\t\tconst target = newest(store)\n\t\t\t\tconst currentSelectorKey =\n\t\t\t\t\tstore.operation.open &&\n\t\t\t\t\tstore.operation.token.type === `writable_pure_selector`\n\t\t\t\t\t\t? store.operation.token.key\n\t\t\t\t\t\t: null\n\t\t\t\tconst currentSelectorTime =\n\t\t\t\t\tstore.operation.open &&\n\t\t\t\t\tstore.operation.token.type === `writable_pure_selector`\n\t\t\t\t\t\t? store.operation.time\n\t\t\t\t\t\t: null\n\n\t\t\t\tconst txUpdateInProgress = target.on.transactionApplying.state?.update\n\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`⏳`,\n\t\t\t\t\t`timeline`,\n\t\t\t\t\ttl.key,\n\t\t\t\t\t`atom`,\n\t\t\t\t\tatomToken.key,\n\t\t\t\t\t`went`,\n\t\t\t\t\tupdate.oldValue,\n\t\t\t\t\t`->`,\n\t\t\t\t\tupdate.newValue,\n\t\t\t\t\ttxUpdateInProgress\n\t\t\t\t\t\t? `in transaction \"${txUpdateInProgress.key}\"`\n\t\t\t\t\t\t: currentSelectorKey\n\t\t\t\t\t\t\t? `in selector \"${currentSelectorKey}\"`\n\t\t\t\t\t\t\t: ``,\n\t\t\t\t)\n\t\t\t\tif (tl.timeTraveling === null) {\n\t\t\t\t\tif (txUpdateInProgress) {\n\t\t\t\t\t\tjoinTransaction(store, tl, txUpdateInProgress)\n\t\t\t\t\t} else if (currentSelectorKey && currentSelectorTime) {\n\t\t\t\t\t\tlet latestUpdate: TimelineUpdate<any> | undefined = tl.history.at(-1)\n\n\t\t\t\t\t\tif (currentSelectorTime !== tl.selectorTime) {\n\t\t\t\t\t\t\tlatestUpdate = {\n\t\t\t\t\t\t\t\ttype: `selector_update`,\n\t\t\t\t\t\t\t\ttimestamp: currentSelectorTime,\n\t\t\t\t\t\t\t\tkey: currentSelectorKey,\n\t\t\t\t\t\t\t\tatomUpdates: [],\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlatestUpdate.atomUpdates.push({\n\t\t\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\t\t...update,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttl.history.push(latestUpdate)\n\n\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t`⌛`,\n\t\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t\t`got a selector_update \"${currentSelectorKey}\" with`,\n\t\t\t\t\t\t\t\tlatestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),\n\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\t\ttl.selectorTime = currentSelectorTime\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (latestUpdate?.type === `selector_update`) {\n\t\t\t\t\t\t\t\tlatestUpdate.atomUpdates.push({\n\t\t\t\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\t\t\t...update,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t\t`⌛`,\n\t\t\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t\t\t`set selector_update \"${currentSelectorKey}\" to`,\n\t\t\t\t\t\t\t\t\tlatestUpdate?.atomUpdates.map((atomUpdate) => atomUpdate.key),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (latestUpdate) {\n\t\t\t\t\t\t\tconst willCaptureSelectorUpdate =\n\t\t\t\t\t\t\t\ttl.shouldCapture?.(latestUpdate, tl) ?? true\n\t\t\t\t\t\t\tif (willCaptureSelectorUpdate) {\n\t\t\t\t\t\t\t\ttl.subject.next(latestUpdate)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\ttl.history.pop()\n\t\t\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst timestamp = Date.now()\n\t\t\t\t\t\ttl.selectorTime = null\n\t\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst atomUpdate: TimelineAtomUpdate<any> = {\n\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\t\toldValue: update.oldValue,\n\t\t\t\t\t\t\tnewValue: update.newValue,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (atom.family) {\n\t\t\t\t\t\t\tatomUpdate.family = atom.family\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true\n\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t`⌛`,\n\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t`got an atom_update to \"${atom.key}\"`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (willCapture) {\n\t\t\t\t\t\t\ttl.history.push(atomUpdate)\n\t\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\t\ttl.subject.next(atomUpdate)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t),\n\t)\n}\n\nfunction addAtomFamilyToTimeline(\n\tstore: Store,\n\tatomFamilyToken: AtomFamilyToken<any, any>,\n\ttl: Timeline<any>,\n): void {\n\tconst family = withdraw(store, atomFamilyToken)\n\tstore.timelineTopics.set(\n\t\t{ topicKey: family.key, timelineKey: tl.key },\n\t\t{ topicType: `atom_family` },\n\t)\n\ttl.subscriptions.set(\n\t\tfamily.key,\n\t\tfamily.subject.subscribe(\n\t\t\t`timeline`,\n\t\t\tfunction timelineCapturesStateLifecycleEvent(creationOrDisposal) {\n\t\t\t\thandleStateLifecycleEvent(store, creationOrDisposal, tl)\n\t\t\t},\n\t\t),\n\t)\n\tfor (const atom of store.atoms.values()) {\n\t\tif (atom.family?.key === family.key) {\n\t\t\taddAtomToTimeline(store, atom, tl)\n\t\t}\n\t}\n}\n\nfunction joinTransaction(\n\tstore: Store,\n\ttl: Timeline<any>,\n\ttxUpdateInProgress: TransactionUpdate<Func>,\n) {\n\tconst currentTxKey = txUpdateInProgress.key\n\tconst currentTxInstanceId = txUpdateInProgress.id\n\tconst currentTxToken: TransactionToken<any> = {\n\t\tkey: currentTxKey,\n\t\ttype: `transaction`,\n\t}\n\tconst currentTransaction = withdraw(store, currentTxToken)\n\tif (currentTxKey && tl.transactionKey === null) {\n\t\ttl.transactionKey = currentTxKey\n\t\tconst unsubscribe = currentTransaction.subject.subscribe(\n\t\t\t`timeline:${tl.key}`,\n\t\t\t(transactionUpdate) => {\n\t\t\t\tunsubscribe()\n\t\t\t\ttl.transactionKey = null\n\t\t\t\tif (tl.timeTraveling === null && currentTxInstanceId) {\n\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t}\n\n\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we are in the context of this timeline\n\t\t\t\t\tconst timelineTopics = store.timelineTopics.getRelatedKeys(tl.key)!\n\n\t\t\t\t\tconst updates = filterTransactionUpdates(\n\t\t\t\t\t\ttransactionUpdate.updates,\n\t\t\t\t\t\ttimelineTopics,\n\t\t\t\t\t)\n\n\t\t\t\t\tconst timelineTransactionUpdate: TimelineTransactionUpdate = {\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t...transactionUpdate,\n\t\t\t\t\t\tupdates,\n\t\t\t\t\t}\n\t\t\t\t\tconst willCapture =\n\t\t\t\t\t\ttl.shouldCapture?.(timelineTransactionUpdate, tl) ?? true\n\t\t\t\t\tif (willCapture) {\n\t\t\t\t\t\ttl.history.push(timelineTransactionUpdate)\n\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\ttl.subject.next(timelineTransactionUpdate)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n}\n\nfunction filterTransactionUpdates(\n\tupdates: TransactionUpdateContent[],\n\ttimelineTopics: Set<string>,\n): TransactionUpdateContent[] {\n\treturn updates\n\t\t.filter((updateFromTx) => {\n\t\t\tif (updateFromTx.type === `transaction_update`) {\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\tlet key: string\n\t\t\tlet familyKey: string | undefined\n\t\t\tswitch (updateFromTx.type) {\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\tkey = updateFromTx.token.key\n\t\t\t\t\tfamilyKey = updateFromTx.token.family?.key\n\t\t\t\t\tbreak\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\t\treturn true // always include\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `selector_update`:\n\t\t\t\t\tkey = updateFromTx.key\n\t\t\t\t\tfamilyKey = updateFromTx.family?.key\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t\ttimelineTopics.has(key)\n\t\t\tif (familyKey && timelineTopics.has(familyKey)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn timelineTopics.has(key)\n\t\t})\n\t\t.map((updateFromTx) => {\n\t\t\tif (`updates` in updateFromTx) {\n\t\t\t\treturn {\n\t\t\t\t\t...updateFromTx,\n\t\t\t\t\tupdates: filterTransactionUpdates(\n\t\t\t\t\t\tupdateFromTx.updates,\n\t\t\t\t\t\ttimelineTopics,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn updateFromTx\n\t\t})\n}\n\nfunction handleStateLifecycleEvent(\n\tstore: Store,\n\tevent: StateCreation<any> | StateDisposal<any>,\n\ttl: Timeline<any>,\n): void {\n\tconst timestamp = Date.now()\n\tconst timelineEvent = Object.assign(event, {\n\t\ttimestamp,\n\t}) as TimelineUpdate<any>\n\tif (!tl.timeTraveling) {\n\t\tconst target = newest(store)\n\t\tif (isChildStore(target)) {\n\t\t\t// we don't want to update the true timeline while we are in a transaction\n\t\t} else {\n\t\t\tconst txUpdateInProgress = target.on.transactionApplying.state\n\t\t\tif (txUpdateInProgress) {\n\t\t\t\tjoinTransaction(store, tl, txUpdateInProgress.update)\n\t\t\t} else {\n\t\t\t\ttl.history.push(timelineEvent)\n\t\t\t\ttl.at = tl.history.length\n\t\t\t\ttl.subject.next(timelineEvent)\n\t\t\t}\n\t\t}\n\t}\n\tswitch (event.type) {\n\t\tcase `state_creation`:\n\t\t\taddAtomToTimeline(store, event.token, tl)\n\t\t\tbreak\n\t\tcase `state_disposal`:\n\t\t\ttl.subscriptions.get(event.token.key)?.()\n\t\t\ttl.subscriptions.delete(event.token.key)\n\t\t\tbreak\n\t}\n}\n","import type { TimelineToken } from \"atom.io\"\n\nimport {\n\tingestAtomUpdate,\n\tingestCreationEvent,\n\tingestDisposalEvent,\n\tingestSelectorUpdate,\n\tingestTransactionUpdate,\n} from \"../ingest-updates\"\nimport type { Store } from \"../store\"\n\nexport const timeTravel = (\n\tstore: Store,\n\taction: `redo` | `undo`,\n\ttoken: TimelineToken<any>,\n): void => {\n\tstore.logger.info(\n\t\taction === `redo` ? `⏩` : `⏪`,\n\t\t`timeline`,\n\t\ttoken.key,\n\t\taction,\n\t)\n\tconst timelineData = store.timelines.get(token.key)\n\tif (!timelineData) {\n\t\tstore.logger.error(\n\t\t\t`🐞`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Failed to ${action}. This timeline has not been initialized.`,\n\t\t)\n\t\treturn\n\t}\n\tif (\n\t\t(action === `redo` && timelineData.at === timelineData.history.length) ||\n\t\t(action === `undo` && timelineData.at === 0)\n\t) {\n\t\tstore.logger.warn(\n\t\t\t`💁`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Failed to ${action} at the ${\n\t\t\t\taction === `redo` ? `end` : `beginning`\n\t\t\t} of timeline \"${token.key}\". There is nothing to ${action}.`,\n\t\t)\n\t\treturn\n\t}\n\n\ttimelineData.timeTraveling = action === `redo` ? `into_future` : `into_past`\n\tif (action === `undo`) {\n\t\t--timelineData.at\n\t}\n\n\tconst update = timelineData.history[timelineData.at]\n\tconst applying = action === `redo` ? `newValue` : `oldValue`\n\n\tswitch (update.type) {\n\t\tcase `atom_update`: {\n\t\t\tingestAtomUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `selector_update`: {\n\t\t\tingestSelectorUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `transaction_update`: {\n\t\t\tingestTransactionUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `state_creation`: {\n\t\t\tingestCreationEvent(update, applying, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `state_disposal`: {\n\t\t\tingestDisposalEvent(update, applying, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `molecule_creation`:\n\t\tcase `molecule_disposal`:\n\t}\n\n\tif (action === `redo`) {\n\t\t++timelineData.at\n\t}\n\n\ttimelineData.subject.next(action)\n\ttimelineData.timeTraveling = null\n\tstore.logger.info(\n\t\t`⏹️`,\n\t\t`timeline`,\n\t\ttoken.key,\n\t\t`\"${token.key}\" is now at ${timelineData.at} / ${timelineData.history.length}`,\n\t)\n}\n"],"mappings":";;;;;;AAAA,SAAgB,UAAUA,SAAuB,KAAK,QAAgB;AACrE,QAAO,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;AACrC;;;;ACID,SAAgB,OAA0BC,OAAa;AACtD,QAAO,MAAM,UAAU,MACtB,QAAQ,MAAM;AAEf,QAAO;AACP;;;;ACXD,IAAa,iBAAb,MAAa,eAAkB;CAC9B,AAAU;CACV,AAAU,SAAS;CAGnB,AAAO,YAAYC,eAA6B;EAC/C,IAAIC;AACJ,MAAI,OAAO,kBAAkB,CAAC,MAAM,CAAC,EACpC,SAAS;OAET,SAAS,cAAc;EAExB,KAAK,UAAU,MAAM,KAAK,EAAE,OAAQ,EAAC;CACrC;CAED,IAAW,SAAuC;AACjD,SAAO,KAAK;CACZ;CAED,IAAW,QAAgB;AAC1B,SAAO,KAAK;CACZ;CAED,AAAO,IAAIC,MAAe;EACzB,KAAK,QAAQ,KAAK,UAAU;EAC5B,KAAK,UAAU,KAAK,SAAS,KAAK,KAAK,QAAQ;CAC/C;CAED,AAAO,OAA0B;EAChC,MAAM,OAAO,IAAI,eAAkB,CAAC,GAAG,KAAK,OAAQ;EACpD,KAAK,SAAS,KAAK;AACnB,SAAO;CACP;AACD;;;;ACVD,MAAa,4BAA4B;CACxC,aAAa,CAAC,IAAI,CAAC;CACnB,iBAAiB,CAAC,QAAQ,CAAC;CAC3B,qBAAqB,CAAC,YAAY,CAAC;CACnC,+BAA+B,CAAC,sBAAsB,CAAC;CACvD,+BAA+B,CAAC,sBAAsB,CAAC;CACvD,+BAA+B,CAAC,sBAAsB,CAAC;CACvD,+BAA+B,CAAC,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;CAGhB,aAAa,QAAQ,KAAK,OAAO;CACjC,aAAa,gBAAgB;CAC7B,MAAM,OAAO,KACZ,CAAC,EAAE,CAAC,EACJ,CAAC,QAAQ,CAAC,EACV,MAAM,KACN,CAAC,CAAC,EAAE,MAAM,IAAI,YAAY,EAAE,aAAa,GAAG,GAAG,EAAE,aAAa,QAAQ,QAAQ,CAC9E;AACD"}
1
+ {"version":3,"file":"index.js","names":["random: () => number","scion: T","lengthOrArray: T[] | number","length: number","item: T","token: ReadableFamilyToken<any, any>","key: Canonical","state: AtomIOInternalResource","a: AType","b: BType","key: AType | BType","x: AType | BType","ys: AType[] | BType[]","x: XType","ys: YType[]","a: AType | undefined","b: BType | undefined","contentKey: string","content: Content","data: JunctionSchema<ASide, BSide> &\n\t\t\tPartial<JunctionEntries<NoInfer<AType>, NoInfer<BType>, Content>>","config?: JunctionAdvancedConfiguration<AType, BType, Content>","content: Content | undefined","x:\n\t\t\t| AType\n\t\t\t| BType\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>","b?: AType | BType","singleRelation: AType | BType | undefined","relations: Content extends null ? YType[] : Record<YType, Content>","config?: { reckless: boolean }","input: Record<ASide, AType> | Record<BSide, BType>","a: AType | BType","key: string","subscriber: this[`Subscriber`]","value: T","initialState: T","store: Store","state: ReadableState<T>","store: Store","token: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>","handleUpdate: (update: any) => void","key: string","arbitrary","subscribeToState","subscribeToTransaction","subscribeToTimeline","executor:\n\t\t\t| Promise<T>\n\t\t\t| ((resolve: (value: T) => void, reject: (reason?: any) => void) => void)","superResolve: ((value: T) => void) | undefined","superReject: ((reason?: any) => void) | undefined","promise: Promise<T>","value: T","reason: any","value: Promise<T> | T","target: Store","atom: MutableAtom<T, any>","origin: Store","store: Store","store: Store","token: ReadableToken<any>","key: string","store: Store","atom: Atom<any>","selector: Selector<any>","target: Store","key: string","value: T","subject: Subject<StateUpdate<unknown>>","state: ReadableState<any>","target: Store","state: ReadableState<T>","defaultValue: T","target: Store","selector: Selector<any>","atom: Atom<any>","nextVersionOfThing: Modify<T> | T","originalThing: T","store: Store","state: Atom<T> | Selector<T>","update: StateUpdate<T>","target: Store","atom: Atom<T>","next: T | ((oldValue: T) => T)","atomUpdate: KeyedStateUpdate<T>","mutableAtom","transceiver: Transceiver<any>","store: Store","state: Atom<any>","state: WritableState<any>","store: Store","token: ReadableToken<any, any>","store: Store","token: WritableToken<T>","family: WritableFamilyToken<T, Canonical> | null","key: Canonical | null","store: Store","state: WritableState<T>","value: T | ((oldValue: T) => T)","store: Store","token: WritableToken<T>","family: WritableFamilyToken<T, Canonical> | null","key: Canonical | null","value: New | ((oldValue: T) => New)","store: Store","key: string","store: Store","key: string","store: Store","selectorKey: string","covered: Set<string>","store: Store","selectorType:\n\t\t| `readonly_held_selector`\n\t\t| `readonly_pure_selector`\n\t\t| `writable_held_selector`\n\t\t| `writable_pure_selector`","selectorKey: string","dependency: ReadonlyPureSelectorToken<unknown> | WritableToken<unknown>","covered: Set<string>","store: Store","selectorType:\n\t\t| `readonly_held_selector`\n\t\t| `readonly_pure_selector`\n\t\t| `writable_held_selector`\n\t\t| `writable_pure_selector`","selectorKey: string","covered: Set<string>","dependency: ReadableToken<any>","token: WritableToken<T>","value: New | ((oldValue: T) => New)","store: Store","options: ReadonlyHeldSelectorOptions<T>","family: FamilyMetadata | undefined","readonlySelector: ReadonlyHeldSelector<T>","s: Store","token: ReadonlyHeldSelectorToken<T>","store: Store","options: ReadonlyPureSelectorOptions<T>","family: FamilyMetadata | undefined","readonlySelector: ReadonlyPureSelector<T>","s: Store","token: ReadonlyPureSelectorToken<T>","store: Store","string: S","token: AtomIOToken","token: AtomIOToken","store: Store","store: Store","token: TransactionToken<F>","id: string","applying: `newValue` | `oldValue`","atomUpdate: KeyedStateUpdate<any>","store: Store","token: RegularAtomToken<unknown>","error: Error","key: S","store: Store","provenance: A","key: V","dependsOn: `all` | `any`","invalidKeys: stringified<Canonical>[]","creationEvent: MoleculeCreation","type: T","sideA: SingularTypedKey<A>","sideB: SingularTypedKey<B>","compoundKey: CompoundTypedKey<T, A, B>","claim: Claim<V>","join","provenance: stringified<Canonical>[]","values: [string, any][]","disposalEvent: MoleculeDisposal","newProvenance: A","exclusive?: `exclusive`","transferEvent: MoleculeTransfer","update: StateCreation<any>","applying: `newValue` | `oldValue`","store: Store","update: StateDisposal<ReadableToken<any>>","update: StateCreation<any> | StateDisposal<any>","update: MoleculeCreation","update: MoleculeDisposal","update: MoleculeTransfer","applying: `newValue` | `oldValue`","selectorUpdate: TimelineSelectorUpdate<any>","store: Store","applying: `newValue` | `oldValue`","transactionUpdate: TransactionUpdate<any>","store: Store","store: RootStore","transactionKey: string","continuityKey: string","store: Store","store: Store","continuityKey: string","newEpoch: number","transactionKey: string","output: ReturnType<F>","store: Store","store: Store","continuityKey: string","transactionKey: string","store: Store","source: Map<K, V>","key: K","value: V","store: Store","key: string","params: any[]","id: string","childBase: Omit<ChildStore, `transactionMeta`>","transactionMeta: TransactionProgress<Func>","child: ChildStore","store: Store","options: TransactionOptions<F>","newTransaction: Transaction<F>","params: Parameters<F>","id: string","target","store: Store","options: WritableHeldSelectorOptions<T>","family: FamilyMetadata | undefined","next: T | ((oldValue: T) => T)","mySelector: WritableHeldSelector<T>","s: Store","token: WritableHeldSelectorToken<T>","store: Store","options: WritablePureSelectorOptions<T>","family: FamilyMetadata | undefined","next: T | ((oldValue: T) => T)","mySelector: WritablePureSelector<T>","s: Store","token: WritablePureSelectorToken<T>","store: Store","options:\n\t\t| ReadonlyHeldSelectorOptions<any>\n\t\t| ReadonlyPureSelectorOptions<any>\n\t\t| WritableHeldSelectorOptions<any>\n\t\t| WritablePureSelectorOptions<any>","state","store: Store","selectorToken: SelectorToken<unknown>","familyToken: SelectorFamilyToken<any, any>","store: Store","options: ReadonlyPureSelectorFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","s: Store","store: Store","options: RegularAtomFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","individualOptions: RegularAtomOptions<T>","atomFamily","s: Store","store: Store","options: ReadonlyHeldSelectorFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","s: Store","store: Store","options: WritableHeldSelectorFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","selectorFamily","s: Store","store: Store","options: WritablePureSelectorFamilyOptions<T, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","selectorFamily","s: Store","store: Store","options:\n\t\t| ReadonlyHeldSelectorFamilyOptions<any, any>\n\t\t| ReadonlyPureSelectorFamilyOptions<any, any>\n\t\t| WritableHeldSelectorFamilyOptions<any, any>\n\t\t| WritablePureSelectorFamilyOptions<any, any>","store: Store","token: ReadableFamilyToken<any, any>","key: Json.Serializable","store: Store","token: ReadableFamilyToken<any, any>","key: Canonical","state: Molecule<any> | ReadableState<any> | undefined","store: Store","token: ReadableFamilyToken<any, any>","key: Canonical","store: Store","token: ReadableToken<any>","store: Store","token: ReadableToken<any>","family: ReadableFamilyToken<any, Canonical> | null","key: Canonical | null","store: Store","token: ReadableToken<T>","key: string","handleUpdate: UpdateHandler<T>","update: StateUpdate<any>","unsubscribe","updateHandler: UpdateHandler<T>","store: Store","token: TimelineToken<ManagedAtom>","key: string","handleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void","store: Store","token: TransactionToken<F>","key: string","handleUpdate: TransactionUpdateHandler<F>","mutableState: MutableAtomToken<Mutable, Json.Serializable>","store: Store","familyMetaData: FamilyMetadata | undefined","mutableState: MutableAtomToken<Mutable, any>","latestUpdateState: RegularAtomToken<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>","target: Store","mutableState: MutableAtomToken<Core, Json.Serializable>","unsubscribe","store: Store","options: MutableAtomOptions<T, J>","family: FamilyMetadata | undefined","newAtom: MutableAtom<T, J>","s: Store","cleanupFunctions: (() => void)[]","handle: UpdateHandler<T>","mutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>","store: Store","store: Store","options: MutableAtomFamilyOptions<T, J, K>","internalRoles?: string[]","key: K","family: FamilyMetadata","individualOptions: MutableAtomOptions<T, J>","atomFamily","s: Store","mutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>","store: Store","jsonFamily: WritablePureSelectorFamily<SerializableCore, Key>","store: Store","mutableAtomToken: MutableAtomToken<Core, SerializableCore>","jsonFamilyToken: WritablePureSelectorFamilyToken<\n\t\t\tSerializableCore,\n\t\t\tstring\n\t\t>","token: WritablePureSelectorToken<SerializableCore>","mutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>","store: Store","updateFamily: AtomFamily<Signal<Core>, Key>","mutableAtomToken: MutableAtomToken<Core, SerializableCore>","updateToken: RegularAtomToken<Signal<Core>>","value: unknown","config: Store[`config`]","store: Store | null","IMPLICIT: { readonly STORE: Store }","store: Store","store: Store","token: AtomIOToken","withdrawn: AtomIOInternalResource | undefined","target: Store | null","store: Store","options: RegularAtomOptions<T>","family: FamilyMetadata | undefined","newAtom: RegularAtom<T>","s: Store","cleanupFunctions: (() => void)[]","handle: UpdateHandler<T>","store: Store","atomToken: AtomToken<unknown>","atomFamily","disposal: AtomDisposal<AtomToken<unknown>>","tokens: AtomIOToken[]","target: Store","source: Store","store: Store","options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>","defaultContent: Content | undefined","Join","token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>","toolkit: WriterToolkit","run: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void","options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>","defaultContent: Content | undefined","store: Store","aSide: ASide","bSide: BSide","getRelatedKeys: Read<\n\t\t\t(key: string) => SetRTX<AType> | SetRTX<BType>\n\t\t>","addRelation: Write<(a: string, b: string) => void>","deleteRelation: Write<(a: string, b: string) => void>","replaceRelationsSafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t>","previousOwnersToDispose: string[]","replaceRelationsUnsafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t>","has: Read<(a: string, b?: string) => boolean>","baseExternalStoreConfiguration: BaseExternalStoreConfiguration","externalStore: ExternalStoreConfiguration<Content>","contentAtoms: RegularAtomFamilyToken<Content, string>","getContent: Read<(key: string) => Content | null>","setContent: Write<(key: string, content: Content) => void>","contentKey: ContentKey","content: Content","states: JoinStateFamilies<\n\t\t\t\t\tASide,\n\t\t\t\t\tAType,\n\t\t\t\t\tBSide,\n\t\t\t\t\tBType,\n\t\t\t\t\tCardinality,\n\t\t\t\t\tContent\n\t\t\t\t>","token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>","store: Store","token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>","change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void","store: Store","token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>","key: AType | BType","store: Store","relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>","token: JoinToken<any, any, any, any, any, any>","store: Store","value: string","store: Store","options: TimelineOptions<ManagedAtom>","data?: Timeline<ManagedAtom>","tl: Timeline<ManagedAtom>","atomToken: AtomToken<ManagedAtom>","familyToken: AtomFamilyToken<any, any>","token: TimelineToken<ManagedAtom>","atomToken: AtomToken<any>","tl: Timeline<any>","latestUpdate: TimelineUpdate<any> | undefined","atomUpdate: TimelineAtomUpdate<any>","atomFamilyToken: AtomFamilyToken<any, any>","txUpdateInProgress: TransactionUpdate<Func>","currentTxToken: TransactionToken<any>","timelineTransactionUpdate: TimelineTransactionUpdate","updates: TransactionUpdateContent[]","timelineTopics: Set<string>","key: string","familyKey: string | undefined","event: StateCreation<any> | StateDisposal<any>","store: Store","action: `redo` | `undo`","token: TimelineToken<any>"],"sources":["../../src/internal/arbitrary.ts","../../src/internal/lineage.ts","../../src/internal/store/circular-buffer.ts","../../src/internal/store/counterfeit.ts","../../src/internal/store/deposit.ts","../../src/internal/junction.ts","../../src/internal/subject.ts","../../src/internal/subscribe/recall-state.ts","../../src/internal/subscribe/subscribe-in-store.ts","../../src/internal/future.ts","../../src/internal/set-state/copy-mutable-if-needed.ts","../../src/internal/transaction/is-root-store.ts","../../src/internal/operation.ts","../../src/internal/set-state/evict-downstream.ts","../../src/internal/caching.ts","../../src/internal/get-state/read-or-compute-value.ts","../../src/internal/subscribe/subscribe-to-root-atoms.ts","../../src/internal/set-state/become.ts","../../src/internal/set-state/emit-update.ts","../../src/internal/set-state/set-atom.ts","../../src/internal/set-state/reset-atom-or-selector.ts","../../src/internal/families/get-family-of-token.ts","../../src/internal/set-state/reset-in-store.ts","../../src/internal/set-state/set-atom-or-selector.ts","../../src/internal/set-state/set-into-store.ts","../../src/internal/keys.ts","../../src/internal/selector/get-selector-dependency-keys.ts","../../src/internal/selector/trace-selector-atoms.ts","../../src/internal/selector/update-selector-atoms.ts","../../src/internal/selector/register-selector.ts","../../src/internal/selector/create-readonly-held-selector.ts","../../src/internal/selector/create-readonly-pure-selector.ts","../../src/internal/transaction/abort-transaction.ts","../../src/internal/capitalize.ts","../../src/internal/pretty-print.ts","../../src/internal/not-found-error.ts","../../src/internal/transaction/act-upon-store.ts","../../src/internal/ingest-updates/ingest-atom-update.ts","../../src/internal/get-trace.ts","../../src/internal/molecule.ts","../../src/internal/ingest-updates/ingest-creation-disposal.ts","../../src/internal/ingest-updates/ingest-selector-update.ts","../../src/internal/ingest-updates/ingest-transaction-update.ts","../../src/internal/transaction/get-epoch-number.ts","../../src/internal/transaction/set-epoch-number.ts","../../src/internal/transaction/apply-transaction.ts","../../src/internal/transaction/assign-transaction-to-continuity.ts","../../src/internal/get-environment-data.ts","../../src/internal/lazy-map.ts","../../src/internal/transaction/build-transaction.ts","../../src/internal/transaction/create-transaction.ts","../../src/internal/transaction/index.ts","../../src/internal/selector/create-writable-held-selector.ts","../../src/internal/selector/create-writable-pure-selector.ts","../../src/internal/selector/create-standalone-selector.ts","../../src/internal/selector/dispose-selector.ts","../../src/internal/families/create-readonly-pure-selector-family.ts","../../src/internal/families/create-regular-atom-family.ts","../../src/internal/families/create-readonly-held-selector-family.ts","../../src/internal/families/create-writable-held-selector-family.ts","../../src/internal/families/create-writable-pure-selector-family.ts","../../src/internal/families/create-selector-family.ts","../../src/internal/families/init-family-member.ts","../../src/internal/families/seek-in-store.ts","../../src/internal/families/find-in-store.ts","../../src/internal/families/dispose-from-store.ts","../../src/internal/get-state/get-from-store.ts","../../src/internal/subscribe/subscribe-to-state.ts","../../src/internal/subscribe/subscribe-to-timeline.ts","../../src/internal/subscribe/subscribe-to-transaction.ts","../../src/internal/mutable/tracker.ts","../../src/internal/mutable/create-mutable-atom.ts","../../src/internal/mutable/tracker-family.ts","../../src/internal/mutable/create-mutable-atom-family.ts","../../src/internal/mutable/get-json-family.ts","../../src/internal/mutable/get-json-token.ts","../../src/internal/mutable/get-update-family.ts","../../src/internal/mutable/get-update-token.ts","../../src/internal/mutable/transceiver.ts","../../src/internal/store/store.ts","../../src/internal/store/withdraw.ts","../../src/internal/atom/create-regular-atom.ts","../../src/internal/atom/dispose-atom.ts","../../src/internal/install-into-store.ts","../../src/internal/join/create-join.ts","../../src/internal/join/join-internal.ts","../../src/internal/join/get-join.ts","../../src/internal/join/edit-relations-in-store.ts","../../src/internal/join/find-relations-in-store.ts","../../src/internal/join/get-internal-relations-from-store.ts","../../src/internal/reserved-keys.ts","../../src/internal/timeline/create-timeline.ts","../../src/internal/timeline/time-travel.ts"],"sourcesContent":["export function arbitrary(random: () => number = Math.random): string {\n\treturn random().toString(36).slice(2)\n}\n","/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\nexport interface Lineage {\n\tparent: typeof this | null\n\tchild: typeof this | null\n}\n\nexport function newest<T extends Lineage>(scion: T): T {\n\twhile (scion.child !== null) {\n\t\tscion = scion.child\n\t}\n\treturn scion\n}\n","export class CircularBuffer<T> {\n\tprotected _buffer: T[]\n\tprotected _index = 0\n\tpublic constructor(array: T[])\n\tpublic constructor(length: number)\n\tpublic constructor(lengthOrArray: T[] | number) {\n\t\tlet length: number\n\t\tif (typeof lengthOrArray === `number`) {\n\t\t\tlength = lengthOrArray\n\t\t} else {\n\t\t\tlength = lengthOrArray.length\n\t\t}\n\t\tthis._buffer = Array.from({ length })\n\t}\n\n\tpublic get buffer(): ReadonlyArray<T | undefined> {\n\t\treturn this._buffer\n\t}\n\n\tpublic get index(): number {\n\t\treturn this._index\n\t}\n\n\tpublic add(item: T): void {\n\t\tthis._buffer[this._index] = item\n\t\tthis._index = (this._index + 1) % this._buffer.length\n\t}\n\n\tpublic copy(): CircularBuffer<T> {\n\t\tconst copy = new CircularBuffer<T>([...this._buffer])\n\t\tcopy._index = this._index\n\t\treturn copy\n\t}\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\n\nexport const FAMILY_MEMBER_TOKEN_TYPES = {\n\tatom_family: `atom`,\n\tmolecule_family: `molecule`,\n\tmutable_atom_family: `mutable_atom`,\n\treadonly_held_selector_family: `readonly_held_selector`,\n\treadonly_pure_selector_family: `readonly_pure_selector`,\n\twritable_held_selector_family: `writable_held_selector`,\n\twritable_pure_selector_family: `writable_pure_selector`,\n} as const\n\nexport function counterfeit<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n\tKey extends K,\n>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n): AtomToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritablePureSelectorToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n): SelectorToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T>\n\nexport function counterfeit<T, K extends Canonical, Key extends K>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T>\n\nexport function counterfeit(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n): ReadableToken<any> {\n\tconst subKey = stringifyJson(key)\n\tconst fullKey = `${token.key}(${subKey})`\n\tconst type = FAMILY_MEMBER_TOKEN_TYPES[token.type]\n\tconst stateToken = {\n\t\tkey: fullKey,\n\t\ttype,\n\t} satisfies ReadableToken<any>\n\n\tObject.assign(stateToken, {\n\t\tfamily: {\n\t\t\tkey: token.key,\n\t\t\tsubKey,\n\t\t},\n\t})\n\n\tObject.assign(stateToken, { counterfeit: true })\n\treturn stateToken\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomIOToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tFunc,\n\tMutableAtom,\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadableState,\n\tReadonlyPureSelector,\n\tReadonlyPureSelectorFamily,\n\tRegularAtom,\n\tRegularAtomFamily,\n\tSelector,\n\tSelectorFamily,\n\tTimeline,\n\tTransceiver,\n\tWritableFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableState,\n} from \"..\"\nimport type { Transaction } from \"../transaction\"\n\nexport function deposit<T>(state: RegularAtom<T>): RegularAtomToken<T>\nexport function deposit<T extends Transceiver<any>>(\n\tstate: MutableAtom<T, any>,\n): MutableAtomToken<T, any>\nexport function deposit<T>(state: Atom<T>): AtomToken<T>\nexport function deposit<T>(\n\tstate: WritablePureSelector<T>,\n): WritablePureSelectorToken<T>\nexport function deposit<T>(\n\tstate: ReadonlyPureSelector<T>,\n): ReadonlyPureSelectorToken<T>\nexport function deposit<T>(state: Selector<T>): SelectorToken<T>\nexport function deposit<T>(state: WritableState<T>): WritableToken<T>\nexport function deposit<T>(state: ReadableState<T>): ReadableToken<T>\n\nexport function deposit<T, K extends Canonical>(\n\tstate: RegularAtomFamily<T, K>,\n): RegularAtomFamilyToken<T, K>\nexport function deposit<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(state: MutableAtomFamily<T, J, K>): MutableAtomFamilyToken<T, J, K>\nexport function deposit<T>(state: AtomFamily<T, any>): AtomFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: WritablePureSelectorFamily<T, any>,\n): WritablePureSelectorFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: ReadonlyPureSelectorFamily<T, any>,\n): ReadonlyPureSelectorFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: SelectorFamily<T, any>,\n): SelectorFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: WritableFamily<T, any>,\n): WritableFamilyToken<T, any>\nexport function deposit<T>(\n\tstate: ReadableFamily<T, any>,\n): ReadableFamilyToken<T, any>\n\nexport function deposit<T extends Func>(\n\tstate: Transaction<T>,\n): TransactionToken<T>\nexport function deposit<M extends TimelineManageable>(\n\tstate: Timeline<M>,\n): TimelineToken<M>\n\nexport function deposit(resource: AtomIOInternalResource): AtomIOToken\n\nexport function deposit(state: AtomIOInternalResource): AtomIOToken {\n\tconst token = {\n\t\tkey: state.key,\n\t\ttype: state.type,\n\t} as any\n\tif (`family` in state) {\n\t\ttoken.family = state.family\n\t}\n\treturn token\n}\n","import type { Json } from \"atom.io/json\"\n\nimport type { Refinement } from \"./utility-types\"\n\nexport type JunctionEntriesBase<\n\tAType extends string,\n\tBType extends string,\n\tContent extends Json.Object | null,\n> = {\n\treadonly relations: ([AType, BType[]] | [BType, AType[]])[]\n\treadonly contents: [string, Content][]\n}\nexport interface JunctionEntries<\n\tAType extends string,\n\tBType extends string,\n\tContent extends Json.Object | null,\n> extends Json.Object,\n\t\tJunctionEntriesBase<AType, BType, Content> {}\n\nexport type JunctionSchemaBase<ASide extends string, BSide extends string> = {\n\t/** Description of the relationship between the two sides */\n\treadonly between: [a: ASide, b: BSide]\n\t/** How many relations are allowed in each direction? */\n\treadonly cardinality: `1:1` | `1:n` | `n:n`\n}\nexport interface JunctionSchema<ASide extends string, BSide extends string>\n\textends Json.Object,\n\t\tJunctionSchemaBase<ASide, BSide> {}\n\nexport type BaseExternalStoreConfiguration = {\n\taddRelation: (a: string, b: string) => void\n\tdeleteRelation: (a: string, b: string) => void\n\treplaceRelationsSafely: (a: string, bs: string[]) => void\n\treplaceRelationsUnsafely: (a: string, bs: string[]) => void\n\tgetRelatedKeys(key: string): Set<string> | undefined\n\thas: (a: string, b?: string) => boolean\n}\n\nexport type ExternalStoreWithContentConfiguration<Content extends Json.Object> =\n\t{\n\t\tgetContent: (contentKey: string) => Content | undefined\n\t\tsetContent: (contentKey: string, content: Content) => void\n\t\tdeleteContent: (contentKey: string) => void\n\t}\n\nexport type Empty<Obj extends object> = {\n\t[Key in keyof Obj]?: undefined\n}\n\nexport type ExternalStoreConfiguration<Content extends Json.Object | null> =\n\tContent extends Json.Object\n\t\t? BaseExternalStoreConfiguration &\n\t\t\t\tExternalStoreWithContentConfiguration<Content>\n\t\t: BaseExternalStoreConfiguration &\n\t\t\t\tEmpty<ExternalStoreWithContentConfiguration<Json.Object>>\n\nexport type JunctionAdvancedConfiguration<\n\tAType extends string,\n\tBType extends string,\n\tContent extends Json.Object | null,\n> = {\n\twarn?: (...args: any[]) => void\n\texternalStore?: ExternalStoreConfiguration<Content>\n\tisAType?: Refinement<string, AType>\n\tisBType?: Refinement<string, BType>\n\tisContent?: Refinement<unknown, Content>\n\tmakeContentKey?: (a: AType, b: BType) => string\n}\n\nexport type JunctionJSON<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tContent extends Json.Object | null,\n> = JunctionEntries<AType, BType, Content> & JunctionSchema<ASide, BSide>\n\nexport class Junction<\n\tconst ASide extends string,\n\tconst AType extends string,\n\tconst BSide extends string,\n\tconst BType extends string,\n\tconst Content extends Json.Object | null = null,\n> {\n\tpublic readonly a: ASide\n\tpublic readonly b: BSide\n\tpublic readonly cardinality: `1:1` | `1:n` | `n:n`\n\tpublic readonly relations: Map<AType | BType, Set<AType> | Set<BType>> =\n\t\tnew Map()\n\tpublic readonly contents: Map<string, Content> = new Map()\n\n\tpublic isAType?: Refinement<string, AType> | null\n\tpublic isBType?: Refinement<string, BType> | null\n\tpublic isContent: Refinement<unknown, Content> | null\n\tpublic makeContentKey = (a: AType, b: BType): string => `${a}:${b}`\n\n\tpublic warn?: (...args: any[]) => void\n\n\tpublic getRelatedKeys(key: AType): Set<BType> | undefined\n\tpublic getRelatedKeys(key: BType): Set<AType> | undefined\n\tpublic getRelatedKeys(key: AType | BType): Set<AType> | Set<BType> | undefined\n\tpublic getRelatedKeys(\n\t\tkey: AType | BType,\n\t): Set<AType> | Set<BType> | undefined {\n\t\treturn this.relations.get(key)\n\t}\n\tprotected addRelation(a: AType, b: BType): void {\n\t\tlet aRelations = this.relations.get(a) as Set<BType> | undefined\n\t\tlet bRelations = this.relations.get(b) as Set<AType> | undefined\n\t\tif (aRelations) {\n\t\t\taRelations.add(b)\n\t\t} else {\n\t\t\taRelations = new Set([b])\n\t\t\tthis.relations.set(a, aRelations)\n\t\t}\n\t\tif (bRelations) {\n\t\t\tbRelations.add(a)\n\t\t} else {\n\t\t\tbRelations = new Set([a])\n\t\t\tthis.relations.set(b, bRelations)\n\t\t}\n\t}\n\tprotected deleteRelation(a: AType, b: BType): void {\n\t\tconst aRelations = this.relations.get(a) as Set<BType> | undefined\n\t\tif (aRelations) {\n\t\t\taRelations.delete(b)\n\t\t\tif (aRelations.size === 0) {\n\t\t\t\tthis.relations.delete(a)\n\t\t\t}\n\t\t\tconst bRelations = this.relations.get(b) as Set<AType> | undefined\n\t\t\tif (bRelations) {\n\t\t\t\tbRelations.delete(a)\n\t\t\t\tif (bRelations.size === 0) {\n\t\t\t\t\tthis.relations.delete(b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected replaceRelationsUnsafely(a: AType, bs: BType[]): void\n\tprotected replaceRelationsUnsafely(b: BType, as: AType[]): void\n\tprotected replaceRelationsUnsafely(\n\t\tx: AType | BType,\n\t\tys: AType[] | BType[],\n\t): void {\n\t\tthis.relations.set(x as AType, new Set(ys as BType[]))\n\t\tfor (const y of ys) {\n\t\t\tconst yRelations = new Set<AType>().add(x as AType)\n\t\t\tthis.relations.set(y, yRelations)\n\t\t}\n\t}\n\tprotected replaceRelationsSafely(a: AType, bs: BType[]): void\n\tprotected replaceRelationsSafely(b: BType, as: AType[]): void\n\tprotected replaceRelationsSafely<\n\t\tXType extends AType | BType,\n\t\tYType extends XType extends AType ? BType : AType,\n\t>(x: XType, ys: YType[]): void {\n\t\tconst xRelationsPrev = this.relations.get(x)\n\t\tlet a: AType | undefined = this.isAType?.(x) ? x : undefined\n\t\tlet b: BType | undefined = a === undefined ? (x as BType) : undefined\n\t\tif (xRelationsPrev) {\n\t\t\tfor (const y of xRelationsPrev) {\n\t\t\t\ta ??= y as AType\n\t\t\t\tb ??= y as BType\n\t\t\t\tconst yRelations = this.relations.get(y) as Set<XType> | undefined\n\t\t\t\tif (yRelations) {\n\t\t\t\t\tif (yRelations.size === 1) {\n\t\t\t\t\t\tthis.relations.delete(y)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tyRelations.delete(x)\n\t\t\t\t\t}\n\t\t\t\t\tthis.contents.delete(this.makeContentKey(a, b))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.relations.set(x, new Set(ys) as any)\n\t\tfor (const y of ys) {\n\t\t\tlet yRelations = this.relations.get(y) as Set<XType> | undefined\n\t\t\tif (yRelations) {\n\t\t\t\tyRelations.add(x)\n\t\t\t} else {\n\t\t\t\tyRelations = new Set<XType>().add(x)\n\t\t\t\tthis.relations.set(y, yRelations as any)\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected getContentInternal(contentKey: string): Content | undefined {\n\t\treturn this.contents.get(contentKey)\n\t}\n\tprotected setContent(contentKey: string, content: Content): void {\n\t\tthis.contents.set(contentKey, content)\n\t}\n\tprotected deleteContent(contentKey: string): void {\n\t\tthis.contents.delete(contentKey)\n\t}\n\n\tpublic constructor(\n\t\tdata: JunctionSchema<ASide, BSide> &\n\t\t\tPartial<JunctionEntries<NoInfer<AType>, NoInfer<BType>, Content>>,\n\t\tconfig?: JunctionAdvancedConfiguration<AType, BType, Content>,\n\t) {\n\t\tthis.a = data.between[0]\n\t\tthis.b = data.between[1]\n\n\t\tthis.cardinality = data.cardinality\n\t\tif (!config?.externalStore) {\n\t\t\tthis.relations = new Map(\n\t\t\t\tdata.relations?.map(([x, ys]) => [x, new Set(ys as AType[])]),\n\t\t\t)\n\t\t\tthis.contents = new Map(data.contents)\n\t\t}\n\t\tthis.isAType = config?.isAType ?? null\n\t\tthis.isBType = config?.isBType ?? null\n\t\tthis.isContent = config?.isContent ?? null\n\t\tif (config?.makeContentKey) {\n\t\t\tthis.makeContentKey = config.makeContentKey\n\t\t}\n\t\tif (config?.externalStore) {\n\t\t\tconst externalStore = config.externalStore\n\t\t\tthis.has = (a, b) => externalStore.has(a, b)\n\t\t\tthis.addRelation = (a, b) => {\n\t\t\t\texternalStore.addRelation(a, b)\n\t\t\t}\n\t\t\tthis.deleteRelation = (a, b) => {\n\t\t\t\texternalStore.deleteRelation(a, b)\n\t\t\t}\n\t\t\tthis.replaceRelationsSafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsSafely(a, bs)\n\t\t\t}\n\t\t\tthis.replaceRelationsUnsafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsUnsafely(a, bs)\n\t\t\t}\n\t\t\tthis.getRelatedKeys = ((key) =>\n\t\t\t\texternalStore.getRelatedKeys(\n\t\t\t\t\tkey,\n\t\t\t\t)) as typeof Junction.prototype.getRelatedKeys\n\t\t\tif (externalStore.getContent) {\n\t\t\t\tthis.getContentInternal = (contentKey) => {\n\t\t\t\t\treturn externalStore.getContent(contentKey) as any\n\t\t\t\t}\n\t\t\t\tthis.setContent = (contentKey, content) => {\n\t\t\t\t\texternalStore.setContent(contentKey, content as any)\n\t\t\t\t}\n\t\t\t\tthis.deleteContent = (contentKey) => {\n\t\t\t\t\texternalStore.deleteContent(contentKey)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [x, ys] of data.relations ?? []) {\n\t\t\t\tlet a = this.isAType?.(x) ? x : undefined\n\t\t\t\tlet b = a === undefined ? (x as BType) : undefined\n\t\t\t\tfor (const y of ys) {\n\t\t\t\t\ta ??= y as AType\n\t\t\t\t\tb ??= y as BType\n\t\t\t\t\tthis.addRelation(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [contentKey, content] of data.contents ?? []) {\n\t\t\t\tthis.setContent(contentKey, content)\n\t\t\t}\n\t\t}\n\t\tif (config?.warn) {\n\t\t\tthis.warn = config.warn\n\t\t}\n\t}\n\tpublic toJSON(): JunctionJSON<ASide, AType, BSide, BType, Content> {\n\t\treturn {\n\t\t\tbetween: [this.a, this.b],\n\t\t\tcardinality: this.cardinality,\n\t\t\trelations: [...this.relations.entries()].map(\n\t\t\t\t([a, b]) => [a, [...b]] as [AType, BType[]],\n\t\t\t),\n\t\t\tcontents: [...this.contents.entries()],\n\t\t}\n\t}\n\n\tpublic set(\n\t\ta: AType,\n\t\t...rest: Content extends null ? [b: BType] : [b: BType, content: Content]\n\t): this\n\tpublic set(\n\t\trelation: { [Key in ASide]: AType } & { [Key in BSide]: BType },\n\t\t...rest: Content extends null ? [] | [void?: undefined] : [content: Content]\n\t): this\n\tpublic set(\n\t\t// a: AType | ({ [Key in ASide]: AType } & { [Key in BSide]: BType }),\n\t\t// ...rest: Content extends null\n\t\t// \t? [] | [b?: BType | undefined]\n\t\t// \t: [b: BType, content: Content] | [content: Content]\n\t\t...params:\n\t\t\t| [\n\t\t\t\t\ta: AType,\n\t\t\t\t\t...rest: Content extends null\n\t\t\t\t\t\t? [b: BType]\n\t\t\t\t\t\t: [b: BType, content: Content],\n\t\t\t ]\n\t\t\t| [\n\t\t\t\t\trelation: { [Key in ASide]: AType } & { [Key in BSide]: BType },\n\t\t\t\t\t...rest: Content extends null\n\t\t\t\t\t\t? [] | [void?: undefined]\n\t\t\t\t\t\t: [content: Content],\n\t\t\t ]\n\t\t// | [{ [Key in ASide]: AType } & { [Key in BSide]: BType }, content: Content]\n\t\t// | [{ [Key in ASide]: AType } & { [Key in BSide]: BType }]\n\t\t// | [a: AType, b: BType, content: Content]\n\t\t// | [a: AType, b: BType]\n\t): this {\n\t\tlet a: AType\n\t\tlet b: BType\n\t\tlet content: Content | undefined\n\t\tswitch (params.length) {\n\t\t\tcase 1: {\n\t\t\t\tconst relation = params[0] as Record<ASide, AType> & Record<BSide, BType>\n\t\t\t\ta = relation[this.a]\n\t\t\t\tb = relation[this.b]\n\t\t\t\tcontent = undefined\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 2: {\n\t\t\t\tconst zeroth = params[0]\n\t\t\t\tif (typeof zeroth === `string`) {\n\t\t\t\t\t;[a, b] = params as unknown as [AType, BType]\n\t\t\t\t} else {\n\t\t\t\t\ta = zeroth[this.a]\n\t\t\t\t\tb = zeroth[this.b]\n\t\t\t\t\tcontent = params[1] as Content\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\ta = params[0] as AType\n\t\t\t\tb = params[1] as BType\n\t\t\t\tcontent = params[2] as Content\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (this.cardinality) {\n\t\t\t// biome-ignore lint/suspicious/noFallthroughSwitchClause: perfect here\n\t\t\tcase `1:1`: {\n\t\t\t\tconst bPrev = this.getRelatedKey(a)\n\t\t\t\tif (bPrev && bPrev !== b) this.delete(a, bPrev)\n\t\t\t}\n\t\t\tcase `1:n`:\n\t\t\t\t{\n\t\t\t\t\tconst aPrev = this.getRelatedKey(b)\n\t\t\t\t\tif (aPrev && aPrev !== a) this.delete(aPrev, b)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `n:n`: // do nothing\n\t\t}\n\t\tif (content) {\n\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\tthis.setContent(contentKey, content)\n\t\t}\n\t\tthis.addRelation(a, b)\n\t\treturn this\n\t}\n\n\tpublic delete(a: AType, b?: BType): this\n\tpublic delete(b: BType, a?: AType): this\n\tpublic delete(\n\t\trelation:\n\t\t\t| { [Key in ASide]: AType }\n\t\t\t| { [Key in BSide]: BType }\n\t\t\t| ({ [Key in ASide]: AType } & { [Key in BSide]: BType }),\n\t\tb?: undefined,\n\t): this\n\tpublic delete(\n\t\tx:\n\t\t\t| AType\n\t\t\t| BType\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>,\n\t\tb?: AType | BType,\n\t): this {\n\t\t// @ts-expect-error we deduce that this.b may index x\n\t\tb = typeof b === `string` ? (b as BType) : (x[this.b] as BType | undefined)\n\t\tconst a =\n\t\t\t// @ts-expect-error we deduce that this.a may index x\n\t\t\ttypeof x === `string` ? (x as AType) : (x[this.a] as AType | undefined)\n\n\t\tif (a === undefined && typeof b === `string`) {\n\t\t\tconst bRelations = this.getRelatedKeys(b) as Set<AType>\n\t\t\tif (bRelations) {\n\t\t\t\tfor (const bRelation of bRelations) {\n\t\t\t\t\tthis.delete(bRelation, b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && b === undefined) {\n\t\t\tconst aRelations = this.getRelatedKeys(a)\n\t\t\tif (aRelations) {\n\t\t\t\tfor (const aRelation of aRelations) {\n\t\t\t\t\tthis.delete(a, aRelation)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && typeof b === `string`) {\n\t\t\tthis.deleteRelation(a, b)\n\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\tthis.deleteContent(contentKey)\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic getRelatedKey(key: AType): BType | undefined\n\tpublic getRelatedKey(key: BType): AType | undefined\n\tpublic getRelatedKey(key: AType | BType): AType | BType | undefined {\n\t\tconst relations = this.getRelatedKeys(key)\n\t\tif (relations) {\n\t\t\tif (relations.size > 1) {\n\t\t\t\tthis.warn?.(\n\t\t\t\t\t`${relations.size} related keys were found for key \"${key}\": (${[\n\t\t\t\t\t\t...relations,\n\t\t\t\t\t]\n\t\t\t\t\t\t.map((k) => `\"${k}\"`)\n\t\t\t\t\t\t.join(`, `)}). Only one related key was expected.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tlet singleRelation: AType | BType | undefined\n\t\t\tfor (const relation of relations) {\n\t\t\t\tsingleRelation = relation\n\t\t\t\tbreak\n\t\t\t}\n\t\t\treturn singleRelation\n\t\t}\n\t}\n\n\tpublic replaceRelations(\n\t\ta: AType,\n\t\trelations: Content extends null ? BType[] : Record<BType, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this\n\tpublic replaceRelations(\n\t\tb: BType,\n\t\trelations: Content extends null ? AType[] : Record<AType, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this\n\tpublic replaceRelations<\n\t\tXType extends AType | BType,\n\t\tYType extends XType extends AType ? BType : AType,\n\t>(\n\t\tx: XType,\n\t\trelations: Content extends null ? YType[] : Record<YType, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this {\n\t\tconst hasContent = !Array.isArray(relations)\n\t\tconst ys = (hasContent ? Object.keys(relations) : relations) as YType[]\n\t\tif (config?.reckless) {\n\t\t\tthis.replaceRelationsUnsafely(x as any, ys as any)\n\t\t} else {\n\t\t\tthis.replaceRelationsSafely(x as any, ys as any)\n\t\t}\n\t\tif (hasContent) {\n\t\t\tfor (const y of ys) {\n\t\t\t\tconst contentKey = this.makeContentKey(x as any, y as any) // sort XY to AB ❗\n\t\t\t\tconst content = (relations as Record<YType, Content>)[y]\n\t\t\t\tthis.setContent(contentKey, content)\n\t\t\t}\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic getContent(a: AType, b: BType): Content | undefined {\n\t\tconst contentKey = this.makeContentKey(a, b)\n\t\treturn this.getContentInternal(contentKey)\n\t}\n\n\tpublic getRelationEntries(input: Record<ASide, AType>): [BType, Content][]\n\tpublic getRelationEntries(input: Record<BSide, BType>): [AType, Content][]\n\tpublic getRelationEntries(\n\t\tinput: Record<ASide, AType> | Record<BSide, BType>,\n\t): [AType | BType, Content][] {\n\t\tconst a: AType | undefined = (input as any)[this.a]\n\t\tconst b: BType | undefined = (input as any)[this.b]\n\t\tif (a !== undefined && b === undefined) {\n\t\t\tconst aRelations = this.getRelatedKeys(a)\n\t\t\tif (aRelations) {\n\t\t\t\treturn [...aRelations].map((aRelation) => {\n\t\t\t\t\treturn [aRelation, this.getContent(a, aRelation) as Content]\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\tif (a === undefined && b !== undefined) {\n\t\t\tconst bRelations = this.getRelatedKeys(b)\n\t\t\tif (bRelations) {\n\t\t\t\treturn [...bRelations].map((bRelation) => {\n\t\t\t\t\treturn [bRelation, this.getContent(bRelation, b) as Content]\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn []\n\t}\n\n\tpublic has(a: AType, b?: BType): boolean\n\tpublic has(b: BType, a?: AType): boolean\n\tpublic has(a: AType | BType, b?: AType | BType): boolean {\n\t\tif (b) {\n\t\t\tconst setA = this.getRelatedKeys(a)\n\t\t\treturn setA?.has(b as any) ?? false\n\t\t}\n\t\treturn this.relations.has(a)\n\t}\n}\n","export class Subject<T> {\n\tpublic Subscriber!: (value: T) => void\n\n\tpublic subscribers: Map<string, this[`Subscriber`]> = new Map()\n\n\tpublic subscribe(key: string, subscriber: this[`Subscriber`]): () => void {\n\t\tthis.subscribers.set(key, subscriber)\n\t\tconst unsubscribe = () => {\n\t\t\tthis.unsubscribe(key)\n\t\t}\n\t\treturn unsubscribe\n\t}\n\n\tprivate unsubscribe(key: string) {\n\t\tthis.subscribers.delete(key)\n\t}\n\n\tpublic next(value: T): void {\n\t\tconst subscribers = this.subscribers.values()\n\t\tfor (const subscriber of subscribers) {\n\t\t\tsubscriber(value)\n\t\t}\n\t}\n}\n\nexport class StatefulSubject<T> extends Subject<T> {\n\tpublic state: T\n\n\tpublic constructor(initialState: T) {\n\t\tsuper()\n\t\tthis.state = initialState\n\t}\n\n\tpublic next(value: T): void {\n\t\tthis.state = value\n\t\tsuper.next(value)\n\t}\n}\n","import type { ReadableState } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const recallState = <T>(store: Store, state: ReadableState<T>): T => {\n\tconst target = newest(store)\n\tif (target.operation.open) {\n\t\treturn target.operation.prev.get(state.key)\n\t}\n\treturn target.valueMap.get(state.key)\n}\n","import type {\n\tReadableToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdateHandler,\n\tUpdateHandler,\n} from \"atom.io\"\nimport type { Func, Store } from \"atom.io/internal\"\nimport {\n\tarbitrary,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nexport function subscribeInStore<T>(\n\tstore: Store,\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n): () => void\nexport function subscribeInStore<F extends Func>(\n\tstore: Store,\n\ttoken: TransactionToken<F>,\n\thandleUpdate: TransactionUpdateHandler<F>,\n\tkey?: string,\n): () => void\nexport function subscribeInStore<M extends TimelineManageable>(\n\tstore: Store,\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n): () => void\nexport function subscribeInStore<M extends TimelineManageable>(\n\tstore: Store,\n\ttoken: ReadableToken<any> | TimelineToken<M> | TransactionToken<any>,\n\thandleUpdate:\n\t\t| TransactionUpdateHandler<any>\n\t\t| UpdateHandler<any>\n\t\t| ((update: TimelineUpdate<M> | `redo` | `undo`) => void),\n\tkey?: string,\n): () => void\nexport function subscribeInStore(\n\tstore: Store,\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = arbitrary(),\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `readonly_held_selector`:\n\t\tcase `writable_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\treturn subscribeToState(store, token, key, handleUpdate)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(store, token, key, handleUpdate)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(store, token, key, handleUpdate)\n\t}\n}\n","/**\n * A Promise whose incoming value can be hot swapped.\n * @internal\n * @private\n * @typeParam T The type of the value that the promise will resolve to.\n *\n * @remarks\n * Can be constructed like a Promise, or from an existing Promise.\n */\nexport class Future<T> extends Promise<T> {\n\tprivate fate: Promise<T> | undefined\n\tprivate resolve: (value: T) => void\n\tprivate reject: (reason?: any) => void\n\n\tpublic done = false\n\n\tpublic constructor(\n\t\texecutor:\n\t\t\t| Promise<T>\n\t\t\t| ((resolve: (value: T) => void, reject: (reason?: any) => void) => void),\n\t) {\n\t\tlet superResolve: ((value: T) => void) | undefined\n\t\tlet superReject: ((reason?: any) => void) | undefined\n\t\tsuper((resolve, reject) => {\n\t\t\tsuperResolve = resolve\n\t\t\tsuperReject = reject\n\t\t})\n\t\tthis.resolve = superResolve as (value: T) => void\n\t\tthis.reject = superReject as (reason?: any) => void\n\t\tthis.use(executor instanceof Promise ? executor : new Promise(executor))\n\t}\n\n\tprivate pass(promise: Promise<T>, value: T) {\n\t\tif (promise === this.fate) {\n\t\t\tthis.resolve(value)\n\t\t\tthis.done = true\n\t\t}\n\t}\n\tprivate fail(promise: Promise<T>, reason: any) {\n\t\tif (promise === this.fate) {\n\t\t\tthis.reject(reason)\n\t\t\tthis.done = true\n\t\t}\n\t}\n\n\tpublic use(value: Promise<T> | T): void {\n\t\tif (this === value) {\n\t\t\treturn\n\t\t}\n\t\tif (value instanceof Promise) {\n\t\t\tconst promise = value\n\t\t\tthis.fate = promise\n\t\t\tpromise.then(\n\t\t\t\t(resolved) => {\n\t\t\t\t\tthis.pass(promise, resolved)\n\t\t\t\t},\n\t\t\t\t(reason) => {\n\t\t\t\t\tthis.fail(promise, reason)\n\t\t\t\t},\n\t\t\t)\n\t\t} else {\n\t\t\tthis.resolve(value)\n\t\t\tthis.fate = undefined\n\t\t}\n\t}\n}\n","import type { MutableAtom, Transceiver } from \"..\"\nimport { Tracker } from \"../mutable\"\nimport type { Store } from \"../store\"\n\nexport function copyMutableIfNeeded<T extends Transceiver<any>>(\n\ttarget: Store,\n\tatom: MutableAtom<T, any>,\n\torigin: Store,\n): T {\n\tconst originValue = origin.valueMap.get(atom.key)\n\tconst targetValue = target.valueMap.get(atom.key)\n\n\tif (originValue !== targetValue) {\n\t\treturn targetValue\n\t}\n\n\tif (originValue === undefined) {\n\t\treturn atom.default()\n\t}\n\n\torigin.logger.info(`📃`, `atom`, atom.key, `copying`)\n\tconst jsonValue = atom.toJson(originValue)\n\tconst copiedValue = atom.fromJson(jsonValue)\n\ttarget.valueMap.set(atom.key, copiedValue)\n\tnew Tracker(atom, origin)\n\treturn copiedValue\n}\n","import type { Store } from \"../store\"\nimport type { Func } from \"../utility-types\"\nimport type { TransactionEpoch, TransactionProgress } from \".\"\n\nexport interface RootStore extends Store {\n\ttransactionMeta: TransactionEpoch\n\tparent: null\n\tchild: ChildStore | null\n}\nexport interface ChildStore extends Store {\n\ttransactionMeta: TransactionProgress<Func>\n\tparent: ChildStore | RootStore\n\tchild: ChildStore | null\n}\n\nexport function isRootStore(store: Store): store is RootStore {\n\treturn `epoch` in store.transactionMeta\n}\n\nexport function isChildStore(store: Store): store is ChildStore {\n\treturn `phase` in store.transactionMeta\n}\n","import type { ReadableToken } from \"atom.io\"\n\nimport type { Store } from \"./store\"\nimport { isChildStore } from \"./transaction/is-root-store\"\n\nexport type OperationProgress =\n\t| {\n\t\t\topen: false\n\t }\n\t| {\n\t\t\topen: true\n\t\t\tdone: Set<string>\n\t\t\tprev: Map<string, any>\n\t\t\ttime: number\n\t\t\ttoken: ReadableToken<any>\n\t }\n\nexport const openOperation = (\n\tstore: Store,\n\ttoken: ReadableToken<any>,\n): number | undefined => {\n\tif (store.operation.open) {\n\t\tconst rejectionTime = performance.now()\n\t\tstore.logger.info(\n\t\t\t`❗`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`deferring setState at T-${rejectionTime} until setState for \"${store.operation.token.key}\" is done`,\n\t\t)\n\t\treturn rejectionTime\n\t}\n\tstore.operation = {\n\t\topen: true,\n\t\tdone: new Set(),\n\t\tprev: new Map(),\n\t\ttime: Date.now(),\n\t\ttoken,\n\t}\n\tstore.logger.info(\n\t\t`⭕`,\n\t\ttoken.type,\n\t\ttoken.key,\n\t\t`operation start in store \"${store.config.name}\"${\n\t\t\t!isChildStore(store)\n\t\t\t\t? ``\n\t\t\t\t: ` ${store.transactionMeta.phase} \"${store.transactionMeta.update.key}\"`\n\t\t}`,\n\t)\n}\nexport const closeOperation = (store: Store): void => {\n\tif (store.operation.open) {\n\t\tstore.logger.info(\n\t\t\t`🔴`,\n\t\t\tstore.operation.token.type,\n\t\t\tstore.operation.token.key,\n\t\t\t`operation done in store \"${store.config.name}\"`,\n\t\t)\n\t}\n\tstore.operation = { open: false }\n\tstore.on.operationClose.next(store.operation)\n}\n\nexport const isDone = (store: Store, key: string): boolean => {\n\tif (!store.operation.open) {\n\t\tstore.logger.error(\n\t\t\t`🐞`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`isDone called outside of an operation. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn true\n\t}\n\treturn store.operation.done.has(key)\n}\nexport const markDone = (store: Store, key: string): void => {\n\tif (!store.operation.open) {\n\t\tstore.logger.error(\n\t\t\t`🐞`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`markDone called outside of an operation. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.operation.done.add(key)\n}\n","import type { Atom, Selector } from \"..\"\nimport { evictCachedValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Store } from \"../store\"\n\nexport function evictDownStream(store: Store, atom: Atom<any>): void {\n\tconst target = newest(store)\n\tconst downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key)\n\ttarget.logger.info(\n\t\t`🧹`,\n\t\tatom.type,\n\t\tatom.key,\n\t\tdownstreamKeys\n\t\t\t? `evicting ${downstreamKeys.size} states downstream:`\n\t\t\t: `no downstream states`,\n\t\tdownstreamKeys ?? `to evict`,\n\t)\n\tif (downstreamKeys) {\n\t\tif (target.operation.open) {\n\t\t\ttarget.logger.info(\n\t\t\t\t`🧹`,\n\t\t\t\tatom.type,\n\t\t\t\tatom.key,\n\t\t\t\t`[ ${[...target.operation.done].join(`, `)} ] already done`,\n\t\t\t)\n\t\t}\n\t\tfor (const key of downstreamKeys) {\n\t\t\tif (isDone(target, key)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tevictCachedValue(target, key)\n\t\t\tmarkDone(target, key)\n\t\t}\n\t}\n}\n\nexport function evictDownStreamFromSelector(\n\tstore: Store,\n\tselector: Selector<any>,\n): void {\n\tconst target = newest(store)\n\tconst relationEntries = target.selectorGraph\n\t\t.getRelationEntries({\n\t\t\tupstreamSelectorKey: selector.key,\n\t\t})\n\t\t.filter(([_, { source }]) => source === selector.key)\n\tfor (const [downstreamSelectorKey] of relationEntries) {\n\t\tif (isDone(target, downstreamSelectorKey)) {\n\t\t\tcontinue\n\t\t}\n\t\tevictCachedValue(target, downstreamSelectorKey)\n\t\tmarkDone(target, downstreamSelectorKey)\n\t}\n}\n","import type { StateUpdate } from \"atom.io\"\n\nimport type { ReadableState } from \".\"\nimport { closeOperation, isChildStore, openOperation } from \".\"\nimport { Future } from \"./future\"\nimport { copyMutableIfNeeded } from \"./set-state/copy-mutable-if-needed\"\nimport {\n\tevictDownStream,\n\tevictDownStreamFromSelector,\n} from \"./set-state/evict-downstream\"\nimport type { Store } from \"./store\"\nimport type { Subject } from \"./subject\"\n\nexport function cacheValue<T>(\n\tstore: Store,\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n): T\nexport function cacheValue<T extends Promise<any>>(\n\tstore: Store,\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n): Future<T>\nexport function cacheValue<T>(\n\ttarget: Store,\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n): Future<T> | T {\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future && !currentValue.done) {\n\t\tconst future = currentValue\n\t\tif (value instanceof Promise) {\n\t\t\tfuture.use(value)\n\t\t\treturn future\n\t\t}\n\t\ttarget.valueMap.set(key, value)\n\t\treturn value\n\t}\n\tif (value instanceof Promise) {\n\t\tconst future = new Future<T>(value)\n\t\ttarget.valueMap.set(key, future)\n\t\tfuture\n\t\t\t.then(function handleResolvedFuture(resolved) {\n\t\t\t\tconst current = target.valueMap.get(key)\n\t\t\t\tif (current === future) {\n\t\t\t\t\tcacheValue(target, key, resolved, subject)\n\t\t\t\t\tconst atom = target.atoms.get(key)\n\t\t\t\t\tif (atom) {\n\t\t\t\t\t\topenOperation(target, atom)\n\t\t\t\t\t\tevictDownStream(target, atom)\n\t\t\t\t\t\tcloseOperation(target)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst selector =\n\t\t\t\t\t\t\ttarget.writableSelectors.get(key) ??\n\t\t\t\t\t\t\ttarget.readonlySelectors.get(key)\n\t\t\t\t\t\tif (selector) {\n\t\t\t\t\t\t\topenOperation(target, selector)\n\t\t\t\t\t\t\tevictDownStreamFromSelector(target, selector)\n\t\t\t\t\t\t\tcloseOperation(target)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsubject.next({ newValue: resolved, oldValue: future })\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch((thrown) => {\n\t\t\t\ttarget.logger.error(`💥`, `state`, key, `rejected:`, thrown)\n\t\t\t})\n\t\treturn future\n\t}\n\ttarget.valueMap.set(key, value)\n\treturn value\n}\n\nexport const readCachedValue = <T>(\n\tstate: ReadableState<any>,\n\ttarget: Store,\n): T => {\n\ttarget.logger.info(`📖`, state.type, state.key, `reading cached value`)\n\tlet value = target.valueMap.get(state.key) as T\n\tif (state.type === `mutable_atom` && isChildStore(target)) {\n\t\tconst { parent } = target\n\t\tconst copiedValue = copyMutableIfNeeded(target, state, parent)\n\t\tvalue = copiedValue\n\t}\n\treturn value\n}\n\nexport const evictCachedValue = (target: Store, key: string): void => {\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future) {\n\t\tconst selector =\n\t\t\ttarget.writableSelectors.get(key) ?? target.readonlySelectors.get(key)\n\t\tif (selector) {\n\t\t\tselector.get()\n\t\t}\n\t\treturn\n\t}\n\tif (target.operation.open) {\n\t\ttarget.operation.prev.set(key, currentValue)\n\t}\n\ttarget.valueMap.delete(key)\n\ttarget.logger.info(`🗑`, `state`, key, `evicted`)\n}\n","import type { ReadableState } from \"..\"\nimport { cacheValue, readCachedValue } from \"../caching\"\nimport type { Store } from \"../store\"\n\nexport const readOrComputeValue = <T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n): T => {\n\tif (target.valueMap.has(state.key)) {\n\t\treturn readCachedValue(state, target)\n\t}\n\tswitch (state.type) {\n\t\tcase `readonly_held_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\tcase `writable_pure_selector`:\n\t\t\ttarget.logger.info(`🧮`, state.type, state.key, `computing value`)\n\t\t\treturn state.get()\n\t\tcase `atom`:\n\t\tcase `mutable_atom`: {\n\t\t\tconst def = state.default\n\t\t\tlet defaultValue: T\n\t\t\tif (def instanceof Function) {\n\t\t\t\tdefaultValue = def()\n\t\t\t} else {\n\t\t\t\tdefaultValue = def\n\t\t\t}\n\t\t\tconst cachedValue = cacheValue(\n\t\t\t\ttarget,\n\t\t\t\tstate.key,\n\t\t\t\tdefaultValue,\n\t\t\t\tstate.subject,\n\t\t\t)\n\t\t\ttarget.logger.info(\n\t\t\t\t`💁`,\n\t\t\t\t`atom`,\n\t\t\t\tstate.key,\n\t\t\t\t`could not find cached value; using default`,\n\t\t\t\tdefaultValue,\n\t\t\t)\n\t\t\treturn cachedValue\n\t\t}\n\t}\n}\n","import type { Atom, Selector } from \"..\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport type { Store } from \"../store\"\nimport { recallState } from \"./recall-state\"\n\nexport const subscribeToRootDependency = (\n\ttarget: Store,\n\tselector: Selector<any>,\n\tatom: Atom<any>,\n): (() => void) => {\n\treturn atom.subject.subscribe(\n\t\t`${selector.type}:${selector.key}`,\n\t\t(atomChange) => {\n\t\t\ttarget.logger.info(\n\t\t\t\t`📢`,\n\t\t\t\tselector.type,\n\t\t\t\tselector.key,\n\t\t\t\t`root`,\n\t\t\t\tatom.key,\n\t\t\t\t`went`,\n\t\t\t\tatomChange.oldValue,\n\t\t\t\t`->`,\n\t\t\t\tatomChange.newValue,\n\t\t\t)\n\t\t\tconst oldValue = recallState(target, selector)\n\t\t\tconst newValue = readOrComputeValue(target, selector)\n\t\t\ttarget.logger.info(\n\t\t\t\t`✨`,\n\t\t\t\tselector.type,\n\t\t\t\tselector.key,\n\t\t\t\t`went`,\n\t\t\t\toldValue,\n\t\t\t\t`->`,\n\t\t\t\tnewValue,\n\t\t\t)\n\t\t\tselector.subject.next({ newValue, oldValue })\n\t\t},\n\t)\n}\n\n// export const subscribeToRootAtoms = (\n// \tstore: Store,\n// \tselector: Selector<any>,\n// ): (() => void)[] => {\n// \tconst target = newest(store)\n// \tconst dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(\n// \t\t(atom) => subscribeToRootDependency(target, selector, atom),\n// \t)\n// \treturn dependencySubscriptions\n// }\n","export type Modify<T> = (thing: T) => T\n\nexport const become =\n\t<T>(nextVersionOfThing: Modify<T> | T) =>\n\t(originalThing: T): T =>\n\t\tnextVersionOfThing instanceof Function\n\t\t\t? nextVersionOfThing(originalThing)\n\t\t\t: nextVersionOfThing\n","import type { StateUpdate } from \"atom.io\"\n\nimport type { Atom, Selector, Store } from \"..\"\n\nexport const emitUpdate = <T>(\n\tstore: Store,\n\tstate: Atom<T> | Selector<T>,\n\tupdate: StateUpdate<T>,\n): void => {\n\tswitch (state.type) {\n\t\tcase `mutable_atom`:\n\t\t\tstore.logger.info(\n\t\t\t\t`📢`,\n\t\t\t\tstate.type,\n\t\t\t\tstate.key,\n\t\t\t\t`is now (`,\n\t\t\t\tupdate.newValue,\n\t\t\t\t`) subscribers:`,\n\t\t\t\tstate.subject.subscribers,\n\t\t\t)\n\t\t\tbreak\n\t\tcase `atom`:\n\t\tcase `writable_pure_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\tcase `readonly_held_selector`:\n\t\t\tstore.logger.info(\n\t\t\t\t`📢`,\n\t\t\t\tstate.type,\n\t\t\t\tstate.key,\n\t\t\t\t`went (`,\n\t\t\t\tupdate.oldValue,\n\t\t\t\t`->`,\n\t\t\t\tupdate.newValue,\n\t\t\t\t`) subscribers:`,\n\t\t\t\tstate.subject.subscribers,\n\t\t\t)\n\t}\n\tstate.subject.next(update)\n}\n","import type { KeyedStateUpdate } from \"atom.io\"\n\nimport type { Atom, Store } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport { isTransceiver, type Transceiver } from \"../mutable\"\nimport { markDone } from \"../operation\"\nimport { isChildStore } from \"../transaction/is-root-store\"\nimport { become } from \"./become\"\nimport { copyMutableIfNeeded } from \"./copy-mutable-if-needed\"\nimport { emitUpdate } from \"./emit-update\"\nimport { evictDownStream } from \"./evict-downstream\"\n\nexport const setAtom = <T>(\n\ttarget: Store,\n\tatom: Atom<T>,\n\tnext: T | ((oldValue: T) => T),\n): void => {\n\tconst oldValue = readOrComputeValue(target, atom)\n\tlet newValue = oldValue\n\tif (atom.type === `mutable_atom` && isChildStore(target)) {\n\t\tconst { parent } = target\n\t\tconst copiedValue = copyMutableIfNeeded(target, atom, parent)\n\t\tnewValue = copiedValue\n\t}\n\tnewValue = become(next)(newValue)\n\ttarget.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)\n\tnewValue = cacheValue(target, atom.key, newValue, atom.subject)\n\tmarkDone(target, atom.key)\n\tevictDownStream(target, atom)\n\tconst update = { oldValue, newValue }\n\tif (!isChildStore(target)) {\n\t\temitUpdate(target, atom, update)\n\t\treturn\n\t}\n\tif (target.on.transactionApplying.state === null) {\n\t\tconst { key } = atom\n\t\tif (isTransceiver(update.newValue)) {\n\t\t\treturn\n\t\t}\n\t\tconst atomUpdate: KeyedStateUpdate<T> = {\n\t\t\ttype: `atom_update`,\n\t\t\tkey,\n\t\t\t...update,\n\t\t}\n\t\tif (atom.family) {\n\t\t\tatomUpdate.family = atom.family\n\t\t}\n\t\ttarget.transactionMeta.update.updates.push(atomUpdate)\n\t\ttarget.logger.info(\n\t\t\t`📁`,\n\t\t\t`atom`,\n\t\t\tkey,\n\t\t\t`stowed (`,\n\t\t\tupdate.oldValue,\n\t\t\t`->`,\n\t\t\tupdate.newValue,\n\t\t\t`)`,\n\t\t)\n\t} else if (atom.key.startsWith(`*`)) {\n\t\tconst mutableKey = atom.key.slice(1)\n\t\tconst mutableAtom = target.atoms.get(mutableKey) as Atom<any>\n\t\tlet transceiver: Transceiver<any> = target.valueMap.get(mutableKey)\n\t\tif (mutableAtom.type === `mutable_atom` && isChildStore(target)) {\n\t\t\tconst { parent } = target\n\t\t\tconst copiedValue = copyMutableIfNeeded(target, mutableAtom, parent)\n\t\t\ttransceiver = copiedValue\n\t\t}\n\t\tconst accepted = transceiver.do(update.newValue) === null\n\t\tif (accepted) evictDownStream(target, mutableAtom)\n\t}\n}\n","import type { Atom, WritableState } from \"..\"\nimport { traceRootSelectorAtoms } from \"..\"\nimport type { Store } from \"../store\"\nimport { setAtom } from \"./set-atom\"\n\nfunction resetAtom(store: Store, state: Atom<any>) {\n\tlet def = state.default\n\tif (def instanceof Function) {\n\t\tdef = def()\n\t}\n\tsetAtom(store, state, def)\n}\n\nexport function resetAtomOrSelector(\n\tstore: Store,\n\tstate: WritableState<any>,\n): void {\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tresetAtom(store, state)\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\t{\n\t\t\t\tconst atoms = traceRootSelectorAtoms(store, state.key)\n\t\t\t\tfor (const atom of atoms.values()) {\n\t\t\t\t\tresetAtom(store, atom)\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t}\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport type { Store } from \"../store\"\n\nexport function getFamilyOfToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\ttoken: MutableAtomToken<T, J, K>,\n): MutableAtomFamilyToken<T, J, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, K>,\n): RegularAtomFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, K>,\n): WritablePureSelectorFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, K>,\n): ReadonlyPureSelectorFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableToken<T, K>,\n): WritableFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K>,\n): ReadableFamilyToken<T, K> | undefined\n\nexport function getFamilyOfToken(\n\tstore: Store,\n\ttoken: ReadableToken<any, any>,\n): ReadableFamilyToken<any, any> | undefined {\n\tif (token.family) {\n\t\tconst family = store.families.get(token.family.key)\n\t\tif (family) {\n\t\t\treturn family\n\t\t}\n\t}\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { type Canonical, parseJson } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { closeOperation, openOperation } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { resetAtomOrSelector } from \"./reset-atom-or-selector\"\n\nexport function resetInStore(store: Store, token: WritableToken<any>): void\n\nexport function resetInStore<K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<any, K>,\n\tkey: K,\n): void\n\nexport function resetInStore<T>(\n\tstore: Store,\n\t...params:\n\t\t| [token: WritableFamilyToken<T, Canonical>, key: Canonical]\n\t\t| [token: WritableToken<T>]\n): void {\n\tlet token: WritableToken<T>\n\tlet family: WritableFamilyToken<T, Canonical> | null\n\tlet key: Canonical | null\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t\tfamily = getFamilyOfToken(store, token) ?? null\n\t\tif (family) {\n\t\t\tkey = token.family ? parseJson(token.family.subKey) : null\n\t\t\ttoken = findInStore(store, family, key)\n\t\t}\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\ttoken = findInStore(store, family, key)\n\t}\n\n\tif (`counterfeit` in token && `family` in token) {\n\t\tconst subKey = token.family.subKey\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === subKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`could not be reset because it was not found in the store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `This state was previously disposed:\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace was found.`,\n\t\t)\n\t\treturn\n\t}\n\n\tconst rejectionTime = openOperation(store, token)\n\tif (rejectionTime) {\n\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t`waiting to reset \"${token.key}\" at T-${rejectionTime}`,\n\t\t\t() => {\n\t\t\t\tunsubscribe()\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🟢`,\n\t\t\t\t\ttoken.type,\n\t\t\t\t\ttoken.key,\n\t\t\t\t\t`resuming deferred resetState from T-${rejectionTime}`,\n\t\t\t\t)\n\t\t\t\tresetInStore(store, token)\n\t\t\t},\n\t\t)\n\t\treturn\n\t}\n\tconst state = withdraw(store, token)\n\tresetAtomOrSelector(store, state)\n\tcloseOperation(store)\n}\n","import type { WritableState } from \"..\"\nimport type { Store } from \"../store\"\nimport { setAtom } from \"./set-atom\"\n\nexport const setAtomOrSelector = <T>(\n\tstore: Store,\n\tstate: WritableState<T>,\n\tvalue: T | ((oldValue: T) => T),\n): void => {\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tsetAtom(store, state, value)\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\tstate.set(value)\n\t\t\tbreak\n\t}\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { type Canonical, parseJson } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { closeOperation, openOperation } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { setAtomOrSelector } from \"./set-atom-or-selector\"\n\nexport function setIntoStore<T, New extends T>(\n\tstore: Store,\n\ttoken: WritableToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n): void\n\nexport function setIntoStore<T, K extends Canonical, New extends T>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: K,\n\tvalue: New | ((oldValue: T) => New),\n): void\n\nexport function setIntoStore<T, New extends T>(\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, Canonical>,\n\t\t\t\tkey: Canonical,\n\t\t\t\tvalue: New | ((oldValue: T) => New),\n\t\t ]\n\t\t| [token: WritableToken<T>, value: New | ((oldValue: T) => New)]\n): void {\n\tlet token: WritableToken<T>\n\tlet family: WritableFamilyToken<T, Canonical> | null\n\tlet key: Canonical | null\n\tlet value: New | ((oldValue: T) => New)\n\tif (params.length === 2) {\n\t\ttoken = params[0]\n\t\tvalue = params[1]\n\t\tfamily = getFamilyOfToken(store, token) ?? null\n\t\tif (family) {\n\t\t\tkey = token.family ? parseJson(token.family.subKey) : null\n\t\t\ttoken = findInStore(store, family, key)\n\t\t}\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\tvalue = params[2]\n\t\ttoken = findInStore(store, family, key)\n\t}\n\n\tif (`counterfeit` in token && `family` in token) {\n\t\tconst subKey = token.family.subKey\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === subKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`could not be set because it was not found in the store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `This state was previously disposed:\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace was found.`,\n\t\t)\n\t\treturn\n\t}\n\n\tconst rejectionTime = openOperation(store, token)\n\tif (rejectionTime) {\n\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t`waiting to set \"${token.key}\" at T-${rejectionTime}`,\n\t\t\t() => {\n\t\t\t\tunsubscribe()\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🟢`,\n\t\t\t\t\ttoken.type,\n\t\t\t\t\ttoken.key,\n\t\t\t\t\t`resuming deferred setState from T-${rejectionTime}`,\n\t\t\t\t)\n\t\t\t\tsetIntoStore(store, token, value)\n\t\t\t},\n\t\t)\n\t\treturn\n\t}\n\tconst state = withdraw(store, token)\n\tsetAtomOrSelector(store, state, value)\n\tcloseOperation(store)\n}\n","import { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\n\nexport type AtomKey<T> = string & { __atomKey?: never; __brand?: T }\nexport type SelectorKey<T> = string & { __selectorKey?: never; __brand?: T }\nexport type ReadonlySelectorKey<T> = string & {\n\t__readonlySelectorKey?: never\n\t__brand?: T\n}\n\nexport const isAtomKey = (store: Store, key: string): key is AtomKey<unknown> =>\n\tnewest(store).atoms.has(key)\nexport const isSelectorKey = (\n\tstore: Store,\n\tkey: string,\n): key is SelectorKey<unknown> => newest(store).writableSelectors.has(key)\nexport const isReadonlySelectorKey = (\n\tstore: Store,\n\tkey: string,\n): key is ReadonlySelectorKey<unknown> =>\n\tnewest(store).readonlySelectors.has(key)\n\nexport type StateKey<T> = AtomKey<T> | ReadonlySelectorKey<T> | SelectorKey<T>\nexport const isStateKey = (\n\tstore: Store,\n\tkey: string,\n): key is StateKey<unknown> =>\n\tisAtomKey(store, key) ||\n\tisSelectorKey(store, key) ||\n\tisReadonlySelectorKey(store, key)\n","import type { AtomKey, ReadonlySelectorKey, SelectorKey } from \"../keys\"\nimport { isStateKey } from \"../keys\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const getSelectorDependencyKeys = (\n\tstore: Store,\n\tkey: string,\n): (\n\t| AtomKey<unknown>\n\t| ReadonlySelectorKey<unknown>\n\t| SelectorKey<unknown>\n)[] => {\n\tconst sources = newest(store)\n\t\t.selectorGraph.getRelationEntries({ downstreamSelectorKey: key })\n\t\t.filter(([_, { source }]) => source !== key)\n\t\t.map(([_, { source }]) => source)\n\t\t.filter((source) => isStateKey(store, source))\n\treturn sources\n}\n","import type { Atom, Store } from \"..\"\nimport { isAtomKey } from \"../keys\"\nimport { getSelectorDependencyKeys } from \"./get-selector-dependency-keys\"\n\nexport const traceRootSelectorAtoms = (\n\tstore: Store,\n\tselectorKey: string,\n\tcovered: Set<string> = new Set<string>(),\n): Map<string, Atom<unknown>> => {\n\tconst dependencies = getSelectorDependencyKeys(store, selectorKey)\n\n\tconst roots = new Map<string, Atom<unknown>>()\n\n\twhile (dependencies.length > 0) {\n\t\t// biome-ignore lint/style/noNonNullAssertion: just checked length ^^^\n\t\tconst dependencyKey = dependencies.pop()!\n\t\tif (covered.has(dependencyKey)) {\n\t\t\tcontinue\n\t\t}\n\t\tcovered.add(dependencyKey)\n\t\tif (isAtomKey(store, dependencyKey)) {\n\t\t\tconst atom = store.atoms.get(dependencyKey) as Atom<unknown>\n\t\t\troots.set(atom.key, atom)\n\t\t} else {\n\t\t\tdependencies.push(...getSelectorDependencyKeys(store, dependencyKey))\n\t\t}\n\t}\n\treturn roots\n}\n","import type { ReadonlyPureSelectorToken, WritableToken } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { traceRootSelectorAtoms } from \"./trace-selector-atoms\"\n\nexport const updateSelectorAtoms = (\n\tstore: Store,\n\tselectorType:\n\t\t| `readonly_held_selector`\n\t\t| `readonly_pure_selector`\n\t\t| `writable_held_selector`\n\t\t| `writable_pure_selector`,\n\tselectorKey: string,\n\tdependency: ReadonlyPureSelectorToken<unknown> | WritableToken<unknown>,\n\tcovered: Set<string>,\n): void => {\n\tconst target = newest(store)\n\tconst { type: dependencyType, key: dependencyKey } = dependency\n\tif (dependencyType === `atom` || dependencyType === `mutable_atom`) {\n\t\ttarget.selectorAtoms.set({\n\t\t\tselectorKey,\n\t\t\tatomKey: dependencyKey,\n\t\t})\n\t\tstore.logger.info(\n\t\t\t`🔍`,\n\t\t\tselectorType,\n\t\t\tselectorKey,\n\t\t\t`discovers root atom \"${dependencyKey}\"`,\n\t\t)\n\t} else {\n\t\tconst rootKeys = traceRootSelectorAtoms(store, dependencyKey, covered)\n\t\tstore.logger.info(\n\t\t\t`🔍`,\n\t\t\tselectorType,\n\t\t\tselectorKey,\n\t\t\t`discovers root atoms: [ ${[...rootKeys.values()]\n\t\t\t\t.map((root) => `\"${root.key}\"`)\n\t\t\t\t.join(`, `)} ]`,\n\t\t)\n\t\tfor (const { key: atomKey } of rootKeys.values()) {\n\t\t\ttarget.selectorAtoms = target.selectorAtoms.set({\n\t\t\t\tselectorKey,\n\t\t\t\tatomKey,\n\t\t\t})\n\t\t}\n\t}\n\tcovered.add(dependencyKey)\n}\n","import type {\n\tfindState,\n\tReadableFamilyToken,\n\tReadableToken,\n\tsetState,\n\tWritableFamilyToken,\n\tWritableToken,\n\tWriterToolkit,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { setAtomOrSelector } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { updateSelectorAtoms } from \"./update-selector-atoms\"\n\nexport const registerSelector = (\n\tstore: Store,\n\tselectorType:\n\t\t| `readonly_held_selector`\n\t\t| `readonly_pure_selector`\n\t\t| `writable_held_selector`\n\t\t| `writable_pure_selector`,\n\tselectorKey: string,\n\tcovered: Set<string>,\n): WriterToolkit => ({\n\tget: (\n\t\t...params:\n\t\t\t| [ReadableFamilyToken<any, any>, Json.Serializable]\n\t\t\t| [ReadableToken<any>]\n\t) => {\n\t\tconst target = newest(store)\n\t\tlet dependency: ReadableToken<any>\n\n\t\tif (params.length === 2) {\n\t\t\tconst [family, key] = params\n\t\t\tdependency = findInStore(store, family, key)\n\t\t} else {\n\t\t\t;[dependency] = params\n\t\t}\n\n\t\tconst dependencyState = withdraw(store, dependency)\n\t\tconst dependencyValue = readOrComputeValue(store, dependencyState)\n\t\tconst dependencyKey = dependency.key\n\n\t\tstore.logger.info(\n\t\t\t`🔌`,\n\t\t\tselectorType,\n\t\t\tselectorKey,\n\t\t\t`registers dependency ( \"${dependencyKey}\" =`,\n\t\t\tdependencyValue,\n\t\t\t`)`,\n\t\t)\n\n\t\ttarget.selectorGraph.set(\n\t\t\t{\n\t\t\t\tupstreamSelectorKey: dependencyKey,\n\t\t\t\tdownstreamSelectorKey: selectorKey,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: dependency.key,\n\t\t\t},\n\t\t)\n\t\tupdateSelectorAtoms(\n\t\t\tstore,\n\t\t\tselectorType,\n\t\t\tselectorKey,\n\t\t\tdependency as any,\n\t\t\tcovered,\n\t\t)\n\t\treturn dependencyValue\n\t},\n\tset: (<T, New extends T>(\n\t\t...params:\n\t\t\t| [\n\t\t\t\t\ttoken: WritableFamilyToken<T, any>,\n\t\t\t\t\tkey: Json.Serializable,\n\t\t\t\t\tvalue: New | ((oldValue: any) => New),\n\t\t\t ]\n\t\t\t| [token: WritableToken<T>, value: New | ((oldValue: T) => New)]\n\t) => {\n\t\tlet token: WritableToken<T>\n\t\tlet value: New | ((oldValue: T) => New)\n\t\tif (params.length === 2) {\n\t\t\ttoken = params[0]\n\t\t\tvalue = params[1]\n\t\t} else {\n\t\t\tconst family = params[0]\n\t\t\tconst key = params[1]\n\t\t\tvalue = params[2]\n\t\t\ttoken = findInStore(store, family, key)\n\t\t}\n\t\tconst target = newest(store)\n\t\tconst state = withdraw(target, token)\n\t\tsetAtomOrSelector(target, state, value)\n\t}) as typeof setState,\n\tfind: ((...args: Parameters<typeof findState>) =>\n\t\tfindInStore(store, ...args)) as typeof findState,\n\tjson: (token) => getJsonToken(store, token),\n})\n","import type {\n\tFamilyMetadata,\n\tReadonlyHeldSelectorOptions,\n\tReadonlyHeldSelectorToken,\n} from \"atom.io\"\n\nimport type { ReadonlyHeldSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadonlyHeldSelector = <T extends object>(\n\tstore: Store,\n\toptions: ReadonlyHeldSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): ReadonlyHeldSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst covered = new Set<string>()\n\tconst { key, const: constant } = options\n\tconst type = `readonly_held_selector` as const\n\tconst { get, find, json } = registerSelector(target, type, key, covered)\n\tconst getSelf = () => {\n\t\tconst innerTarget = newest(store)\n\t\tconst upstreamStates = innerTarget.selectorGraph.getRelationEntries({\n\t\t\tdownstreamSelectorKey: key,\n\t\t})\n\t\tfor (const [downstreamSelectorKey, { source }] of upstreamStates) {\n\t\t\tif (source !== key) {\n\t\t\t\tinnerTarget.selectorGraph.delete(downstreamSelectorKey, key)\n\t\t\t}\n\t\t}\n\t\tinnerTarget.selectorAtoms.delete(key)\n\t\toptions.get({ get, find, json }, constant)\n\t\tcacheValue(newest(store), key, constant, subject)\n\t\tcovered.clear()\n\t\treturn constant\n\t}\n\n\tconst readonlySelector: ReadonlyHeldSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlyHeldSelector(s, options, family),\n\t\tget: getSelf,\n\t\t...(family && { family }),\n\t}\n\ttarget.readonlySelectors.set(key, readonlySelector)\n\tstore.logger.info(`✨`, type, key, `=`, constant)\n\tconst token: ReadonlyHeldSelectorToken<T> = {\n\t\tkey,\n\t\ttype,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyPureSelectorOptions,\n\tReadonlyPureSelectorToken,\n} from \"atom.io\"\n\nimport type { ReadonlyPureSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadonlyPureSelector = <T>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): ReadonlyPureSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst covered = new Set<string>()\n\tconst key = options.key\n\tconst type = `readonly_pure_selector` as const\n\tconst { get, find, json } = registerSelector(target, type, key, covered)\n\tconst getSelf = () => {\n\t\tconst innerTarget = newest(store)\n\t\tconst upstreamStates = innerTarget.selectorGraph.getRelationEntries({\n\t\t\tdownstreamSelectorKey: key,\n\t\t})\n\t\tfor (const [downstreamSelectorKey, { source }] of upstreamStates) {\n\t\t\tif (source !== key) {\n\t\t\t\tinnerTarget.selectorGraph.delete(downstreamSelectorKey, key)\n\t\t\t}\n\t\t}\n\t\tinnerTarget.selectorAtoms.delete(key)\n\t\tconst value = options.get({ get, find, json })\n\t\tconst cached = cacheValue(innerTarget, key, value, subject)\n\t\tstore.logger.info(`✨`, type, key, `=`, cached)\n\t\tcovered.clear()\n\t\treturn cached\n\t}\n\n\tconst readonlySelector: ReadonlyPureSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlyPureSelector(s, options, family),\n\t\tget: getSelf,\n\t\t...(family && { family }),\n\t}\n\ttarget.readonlySelectors.set(key, readonlySelector)\n\tconst token: ReadonlyPureSelectorToken<T> = {\n\t\tkey,\n\t\ttype,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\treturn token\n}\n","import { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { isChildStore } from \"./is-root-store\"\n\nexport const abortTransaction = (store: Store): void => {\n\tconst target = newest(store)\n\tif (!isChildStore(target)) {\n\t\tstore.logger.warn(\n\t\t\t`🐞`,\n\t\t\t`transaction`,\n\t\t\t`???`,\n\t\t\t`abortTransaction called outside of a transaction. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.logger.info(\n\t\t`🪂`,\n\t\t`transaction`,\n\t\ttarget.transactionMeta.update.key,\n\t\t`Aborting transaction`,\n\t)\n\ttarget.parent.child = null\n}\n","export function capitalize<S extends string>(string: S): Capitalize<S> {\n\treturn (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>\n}\n","import type { AtomIOToken } from \"atom.io\"\n\nimport { capitalize } from \"./capitalize\"\n\nexport function prettyPrintTokenType(token: AtomIOToken): string {\n\treturn token.type.split(`_`).map(capitalize).join(` `)\n}\n","import type { AtomIOToken } from \"atom.io\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { prettyPrintTokenType } from \"./pretty-print\"\nimport type { Store } from \"./store\"\n\nexport class NotFoundError extends Error {\n\tpublic constructor(token: AtomIOToken, store: Store) {\n\t\tsuper(\n\t\t\t`${prettyPrintTokenType(token)} ${stringifyJson(token.key)} not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import type { TransactionToken } from \"atom.io\"\n\nimport { NotFoundError } from \"../not-found-error\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Func } from \"../utility-types\"\n\nexport function actUponStore<F extends Func>(\n\tstore: Store,\n\ttoken: TransactionToken<F>,\n\tid: string,\n): (...parameters: Parameters<F>) => ReturnType<F> {\n\treturn (...parameters: Parameters<F>): ReturnType<F> => {\n\t\tconst tx = withdraw(store, token)\n\t\tif (tx) {\n\t\t\treturn tx.run(parameters, id)\n\t\t}\n\t\tthrow new NotFoundError(token, store)\n\t}\n}\n","import type { KeyedStateUpdate, RegularAtomToken } from \"atom.io\"\n\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\n\nexport function ingestAtomUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tatomUpdate: KeyedStateUpdate<any>,\n\tstore: Store,\n): void {\n\tconst { key, newValue, oldValue } = atomUpdate\n\tconst value = applying === `newValue` ? newValue : oldValue\n\tconst token: RegularAtomToken<unknown> = { key, type: `atom` }\n\tif (atomUpdate.family) {\n\t\tObject.assign(token, { family: atomUpdate.family })\n\t}\n\tsetIntoStore(store, token, value)\n}\n","export function getTrace(error: Error): string {\n\tconst { stack } = error\n\tif (stack) {\n\t\treturn `\\n` + stack.split(`\\n`)?.slice(1)?.join(`\\n`)\n\t}\n\treturn ``\n}\n","import type {\n\tAbove,\n\tClaim,\n\tCompoundFrom,\n\tCompoundTypedKey,\n\tHierarchy,\n\tMoleculeCreation,\n\tMoleculeDisposal,\n\tMoleculeTransfer,\n\tSingularTypedKey,\n\tVassal,\n} from \"atom.io\"\nimport type { Canonical, stringified } from \"atom.io/json\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\n\nimport { disposeFromStore, findInStore } from \"./families\"\nimport { getTrace } from \"./get-trace\"\nimport { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\nimport { IMPLICIT } from \"./store\"\nimport { isChildStore } from \"./transaction\"\n\nexport type Molecule<K extends Canonical> = {\n\treadonly key: K\n\treadonly stringKey: stringified<K>\n\treadonly dependsOn: `all` | `any`\n}\n\nexport function makeRootMoleculeInStore<S extends string>(\n\tkey: S,\n\tstore: Store = IMPLICIT.STORE,\n): S {\n\tconst molecule = {\n\t\tkey,\n\t\tstringKey: stringifyJson(key),\n\t\tdependsOn: `any`,\n\t} satisfies Molecule<S>\n\tstore.molecules.set(stringifyJson(key), molecule)\n\treturn key\n}\n\nexport function allocateIntoStore<\n\tH extends Hierarchy,\n\tV extends Vassal<H>,\n\tA extends Above<V, H>,\n>(\n\tstore: Store,\n\tprovenance: A,\n\tkey: V,\n\tdependsOn: `all` | `any` = `any`,\n): Claim<V> {\n\tconst origin = provenance as Canonical | [Canonical, Canonical]\n\tconst stringKey = stringifyJson(key)\n\tconst invalidKeys: stringified<Canonical>[] = []\n\tconst target = newest(store)\n\n\tif (Array.isArray(origin)) {\n\t\tfor (const formerClaim of origin) {\n\t\t\tconst claimString = stringifyJson(formerClaim)\n\t\t\tconst claim = target.molecules.get(claimString)\n\t\t\tif (claim) {\n\t\t\t\tstore.moleculeGraph.set(claimString, stringKey, { source: claimString })\n\t\t\t} else {\n\t\t\t\tinvalidKeys.push(claimString)\n\t\t\t}\n\t\t}\n\t} else {\n\t\tconst claimString = stringifyJson(origin)\n\t\tconst claim = target.molecules.get(claimString)\n\t\tif (claim) {\n\t\t\tstore.moleculeGraph.set(claimString, stringKey, { source: claimString })\n\t\t} else {\n\t\t\tinvalidKeys.push(claimString)\n\t\t}\n\t}\n\tif (invalidKeys.length === 0) {\n\t\ttarget.molecules.set(stringKey, { key, stringKey, dependsOn })\n\t}\n\n\tconst creationEvent: MoleculeCreation = {\n\t\ttype: `molecule_creation`,\n\t\tkey,\n\t\tprovenance: origin,\n\t}\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.updates.push(creationEvent)\n\t} else {\n\t\ttarget.on.moleculeCreation.next(creationEvent)\n\t}\n\n\tfor (const claim of invalidKeys) {\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === claim,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`molecule`,\n\t\t\tkey,\n\t\t\t`allocation failed:`,\n\t\t\t`Could not allocate to ${claim} in store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `\\n ${claim} was most recently disposed\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace for ${claim} was found.`,\n\t\t)\n\t}\n\n\treturn key as Claim<V>\n}\n\nexport function fuseWithinStore<\n\tH extends Hierarchy,\n\tC extends CompoundFrom<H>,\n\tT extends C extends CompoundTypedKey<infer t, any, any> ? t : never,\n\tA extends C extends CompoundTypedKey<any, infer a, any> ? a : never,\n\tB extends C extends CompoundTypedKey<any, any, infer b> ? b : never,\n>(\n\tstore: Store,\n\ttype: T,\n\tsideA: SingularTypedKey<A>,\n\tsideB: SingularTypedKey<B>,\n): Claim<CompoundTypedKey<T, A, B>> {\n\tconst compoundKey: CompoundTypedKey<T, A, B> =\n\t\t`T$--${type}==${sideA}++${sideB}`\n\tconst above = [sideA, sideB] as Above<Vassal<H>, H>\n\tallocateIntoStore<H, Vassal<H>, Above<Vassal<H>, H>>(\n\t\tstore,\n\t\tabove,\n\t\tcompoundKey as Vassal<H>,\n\t\t`all`,\n\t)\n\treturn compoundKey\n}\n\nexport function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(\n\tstore: Store,\n\tclaim: Claim<V>,\n): void {\n\tconst stringKey = stringifyJson(claim)\n\n\tconst molecule = store.molecules.get(stringKey)\n\tif (!molecule) {\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === stringKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`molecule`,\n\t\t\tclaim,\n\t\t\t`deallocation failed:`,\n\t\t\t`Could not find allocation for ${stringKey} in store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `\\n This state was most recently deallocated\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace for ${stringKey} was found.`,\n\t\t)\n\t\treturn\n\t}\n\n\tconst joinKeys = store.moleculeJoins.getRelatedKeys(\n\t\tmolecule.key as string /* 💥 RECONCILE */,\n\t)\n\tif (joinKeys) {\n\t\tfor (const joinKey of joinKeys) {\n\t\t\tconst join = store.joins.get(joinKey)\n\t\t\tif (join) {\n\t\t\t\tjoin.relations.delete(molecule.key)\n\t\t\t\tjoin.molecules.delete(molecule.stringKey) // get rid of\n\t\t\t}\n\t\t}\n\t}\n\tstore.moleculeJoins.delete(molecule.stringKey)\n\n\tconst provenance: stringified<Canonical>[] = []\n\n\tconst values: [string, any][] = []\n\tconst disposalEvent: MoleculeDisposal = {\n\t\ttype: `molecule_disposal`,\n\t\tkey: molecule.key,\n\t\tvalues,\n\t\tprovenance,\n\t}\n\tconst target = newest(store)\n\ttarget.molecules.delete(stringKey)\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.updates.push(disposalEvent)\n\t}\n\tconst relatedMolecules = store.moleculeGraph.getRelationEntries({\n\t\tdownstreamMoleculeKey: molecule.stringKey,\n\t})\n\tif (relatedMolecules) {\n\t\tfor (const [relatedStringKey, { source }] of relatedMolecules) {\n\t\t\tif (source === molecule.stringKey) {\n\t\t\t\tconst relatedKey = parseJson(relatedStringKey)\n\t\t\t\tdeallocateFromStore<any, any>(store, relatedKey)\n\t\t\t} else {\n\t\t\t\tprovenance.push(source)\n\t\t\t}\n\t\t}\n\t}\n\tconst familyKeys = target.moleculeData.getRelatedKeys(molecule.stringKey)\n\tif (familyKeys) {\n\t\tfor (const familyKey of familyKeys) {\n\t\t\t// biome-ignore lint/style/noNonNullAssertion: tokens of molecules must have a family\n\t\t\tconst family = target.families.get(familyKey)!\n\t\t\tconst token = findInStore(store, family, molecule.key)\n\t\t\tvalues.push([family.key, token])\n\t\t\tdisposeFromStore(store, token)\n\t\t}\n\t}\n\n\ttarget.moleculeGraph.delete(molecule.stringKey)\n\ttarget.moleculeJoins.delete(molecule.stringKey)\n\ttarget.moleculeData.delete(molecule.stringKey)\n\n\tif (!isTransaction) {\n\t\ttarget.on.moleculeDisposal.next(disposalEvent)\n\t}\n\ttarget.molecules.delete(molecule.stringKey)\n\n\tconst trace = getTrace(new Error())\n\tstore.disposalTraces.add({ key: stringKey, trace })\n}\nexport function claimWithinStore<\n\tH extends Hierarchy,\n\tV extends Exclude<Vassal<H>, CompoundTypedKey>,\n\tA extends Above<V, H>,\n>(\n\tstore: Store,\n\tnewProvenance: A,\n\tclaim: Claim<V>,\n\texclusive?: `exclusive`,\n): Claim<V> {\n\tconst stringKey = stringifyJson(claim)\n\tconst target = newest(store)\n\tconst molecule = target.molecules.get(stringKey)\n\tif (!molecule) {\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === stringKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`molecule`,\n\t\t\tclaim,\n\t\t\t`claim failed:`,\n\t\t\t`Could not allocate to ${stringKey} in store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `\\n ${stringKey} was most recently disposed\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace for ${stringKey} was found.`,\n\t\t)\n\t\treturn claim\n\t}\n\n\tconst newProvenanceKey = stringifyJson(newProvenance as Canonical)\n\tconst newProvenanceMolecule = target.molecules.get(newProvenanceKey)\n\tif (!newProvenanceMolecule) {\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === newProvenanceKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`molecule`,\n\t\t\tclaim,\n\t\t\t`claim failed:`,\n\t\t\t`Could not allocate to ${newProvenanceKey} in store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `\\n ${newProvenanceKey} was most recently disposed\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace for ${newProvenanceKey} was found.`,\n\t\t)\n\t\treturn claim\n\t}\n\n\tconst priorProvenance = store.moleculeGraph\n\t\t.getRelationEntries({\n\t\t\tdownstreamMoleculeKey: molecule.stringKey,\n\t\t})\n\t\t.filter(([, { source }]) => source !== stringKey)\n\t\t.map(([key]) => parseJson(key))\n\tif (exclusive) {\n\t\ttarget.moleculeGraph.delete(stringKey)\n\t}\n\ttarget.moleculeGraph.set(\n\t\t{\n\t\t\tupstreamMoleculeKey: newProvenanceMolecule.stringKey,\n\t\t\tdownstreamMoleculeKey: molecule.stringKey,\n\t\t},\n\t\t{\n\t\t\tsource: newProvenanceMolecule.stringKey,\n\t\t},\n\t)\n\tconst transferEvent: MoleculeTransfer = {\n\t\ttype: `molecule_transfer`,\n\t\tkey: molecule.key,\n\t\tfrom: priorProvenance,\n\t\tto: [newProvenanceMolecule.key],\n\t}\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.updates.push(transferEvent)\n\t}\n\n\treturn claim\n}\n","import type {\n\tMoleculeCreation,\n\tMoleculeDisposal,\n\tMoleculeTransfer,\n\tReadableToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\n\nimport { disposeFromStore, findInStore } from \"../families\"\nimport {\n\tallocateIntoStore,\n\tclaimWithinStore,\n\tdeallocateFromStore,\n} from \"../molecule\"\nimport type { Store } from \"../store\"\n\nexport function ingestCreationEvent(\n\tupdate: StateCreation<any>,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`: {\n\t\t\tcreateInStore(update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `oldValue`: {\n\t\t\tdisposeFromStore(store, update.token)\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nexport function ingestDisposalEvent(\n\tupdate: StateDisposal<ReadableToken<any>>,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`: {\n\t\t\tdisposeFromStore(store, update.token)\n\t\t\tbreak\n\t\t}\n\t\tcase `oldValue`: {\n\t\t\tcreateInStore(update, store)\n\t\t\tif (update.subType === `atom`) {\n\t\t\t\tstore.valueMap.set(update.token.key, update.value)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nfunction createInStore(\n\tupdate: StateCreation<any> | StateDisposal<any>,\n\tstore: Store,\n): void {\n\tconst { family: familyMeta } = update.token\n\tif (familyMeta) {\n\t\tconst family = store.families.get(familyMeta.key)\n\t\tif (family) {\n\t\t\tfindInStore(store, family, parseJson(familyMeta.subKey))\n\t\t}\n\t}\n}\n\nexport function ingestMoleculeCreationEvent(\n\tupdate: MoleculeCreation,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\tallocateIntoStore<any, any, any>(store, update.provenance, update.key)\n\t\t\tbreak\n\n\t\tcase `oldValue`:\n\t\t\tdeallocateFromStore<any, any>(store, update.key)\n\t\t\tbreak\n\t}\n}\nexport function ingestMoleculeDisposalEvent(\n\tupdate: MoleculeDisposal,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\tdeallocateFromStore<any, any>(store, update.key)\n\t\t\tbreak\n\n\t\tcase `oldValue`:\n\t\t\t{\n\t\t\t\tconst provenanceJson = update.provenance.map(parseJson)\n\t\t\t\tallocateIntoStore<any, any, any>(store, provenanceJson, update.key)\n\t\t\t\tfor (const [familyKey, value] of update.values) {\n\t\t\t\t\tconst family = store.families.get(familyKey)\n\t\t\t\t\tif (family) {\n\t\t\t\t\t\tfindInStore(store, family, update.key)\n\t\t\t\t\t\tconst memberKey = `${familyKey}(${stringifyJson(update.key)})`\n\t\t\t\t\t\tstore.valueMap.set(memberKey, value)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t}\n}\nexport function ingestMoleculeTransferEvent(\n\tupdate: MoleculeTransfer,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\t{\n\t\t\t\tconst provenance = update.to.length === 1 ? update.to[0] : update.to\n\t\t\t\tclaimWithinStore<any, any, any>(\n\t\t\t\t\tstore,\n\t\t\t\t\tprovenance,\n\t\t\t\t\tupdate.key,\n\t\t\t\t\t`exclusive`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tbreak\n\t\tcase `oldValue`:\n\t\t\t{\n\t\t\t\tconst provenance =\n\t\t\t\t\tupdate.from.length === 1 ? update.from[0] : update.from\n\t\t\t\tclaimWithinStore<any, any, any>(\n\t\t\t\t\tstore,\n\t\t\t\t\tprovenance,\n\t\t\t\t\tupdate.key,\n\t\t\t\t\t`exclusive`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tbreak\n\t}\n}\n","import type { Store } from \"../store\"\nimport type { TimelineSelectorUpdate } from \"../timeline\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\n\nexport function ingestSelectorUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tselectorUpdate: TimelineSelectorUpdate<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? selectorUpdate.atomUpdates\n\t\t\t: selectorUpdate.atomUpdates.toReversed()\n\tfor (const atomUpdate of updates) {\n\t\tingestAtomUpdate(applying, atomUpdate, store)\n\t}\n}\n","import type { TransactionUpdate } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\nimport {\n\tingestCreationEvent,\n\tingestDisposalEvent,\n\tingestMoleculeCreationEvent,\n\tingestMoleculeDisposalEvent,\n\tingestMoleculeTransferEvent,\n} from \"./ingest-creation-disposal\"\n\nexport function ingestTransactionUpdate(\n\tapplying: `newValue` | `oldValue`,\n\ttransactionUpdate: TransactionUpdate<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? transactionUpdate.updates\n\t\t\t: [...transactionUpdate.updates].reverse()\n\tfor (const updateFromTransaction of updates) {\n\t\tswitch (updateFromTransaction.type) {\n\t\t\tcase `atom_update`:\n\t\t\tcase `selector_update`:\n\t\t\t\tingestAtomUpdate(applying, updateFromTransaction, store)\n\t\t\t\tbreak\n\t\t\tcase `state_creation`:\n\t\t\t\tingestCreationEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `state_disposal`:\n\t\t\t\tingestDisposalEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `molecule_creation`:\n\t\t\t\tingestMoleculeCreationEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `molecule_disposal`:\n\t\t\t\tingestMoleculeDisposalEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `molecule_transfer`:\n\t\t\t\tingestMoleculeTransferEvent(updateFromTransaction, applying, store)\n\t\t\t\tbreak\n\t\t\tcase `transaction_update`:\n\t\t\t\tingestTransactionUpdate(applying, updateFromTransaction, store)\n\t\t\t\tbreak\n\t\t}\n\t}\n}\n","import type { Store } from \"../store\"\nimport type { RootStore } from \"./is-root-store\"\nimport { isRootStore } from \"./is-root-store\"\n\nexport function getContinuityKey(\n\tstore: RootStore,\n\ttransactionKey: string,\n): string | undefined {\n\tconst continuity =\n\t\tstore.transactionMeta.actionContinuities.getRelatedKey(transactionKey)\n\n\treturn continuity\n}\n\nexport function getEpochNumberOfContinuity(\n\tstore: RootStore,\n\tcontinuityKey: string,\n): number | undefined {\n\tconst epoch = store.transactionMeta.epoch.get(continuityKey)\n\treturn epoch\n}\n\nexport function getEpochNumberOfAction(\n\tstore: Store,\n\ttransactionKey: string,\n): number | undefined {\n\tconst isRoot = isRootStore(store)\n\tif (!isRoot) {\n\t\treturn undefined\n\t}\n\tconst continuityKey = getContinuityKey(store, transactionKey)\n\tif (continuityKey === undefined) {\n\t\treturn undefined\n\t}\n\treturn getEpochNumberOfContinuity(store, continuityKey)\n}\n","import type { Store } from \"../store\"\nimport { getContinuityKey } from \"./get-epoch-number\"\nimport { isRootStore } from \"./is-root-store\"\n\nexport function setEpochNumberOfContinuity(\n\tstore: Store,\n\tcontinuityKey: string,\n\tnewEpoch: number,\n): void {\n\tconst isRoot = isRootStore(store)\n\tif (isRoot && continuityKey) {\n\t\tstore.transactionMeta.epoch.set(continuityKey, newEpoch)\n\t}\n}\n\nexport function setEpochNumberOfAction(\n\tstore: Store,\n\ttransactionKey: string,\n\tnewEpoch: number,\n): void {\n\tconst isRoot = isRootStore(store)\n\tif (!isRoot) {\n\t\treturn\n\t}\n\tconst continuityKey = getContinuityKey(store, transactionKey)\n\n\tif (continuityKey !== undefined) {\n\t\tstore.transactionMeta.epoch.set(continuityKey, newEpoch)\n\t}\n}\n","import { ingestTransactionUpdate } from \"../ingest-updates\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Func } from \"../utility-types\"\nimport { isChildStore, isRootStore } from \"./is-root-store\"\nimport { setEpochNumberOfAction } from \"./set-epoch-number\"\n\nexport const applyTransaction = <F extends Func>(\n\toutput: ReturnType<F>,\n\tstore: Store,\n): void => {\n\tconst child = newest(store)\n\tconst { parent } = child\n\tif (\n\t\tparent === null ||\n\t\t!isChildStore(child) ||\n\t\tchild.transactionMeta?.phase !== `building`\n\t) {\n\t\tstore.logger.warn(\n\t\t\t`🐞`,\n\t\t\t`transaction`,\n\t\t\t`???`,\n\t\t\t`applyTransaction called outside of a transaction. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tchild.transactionMeta.phase = `applying`\n\tchild.transactionMeta.update.output = output\n\tparent.child = null\n\tparent.on.transactionApplying.next(child.transactionMeta)\n\tconst { updates } = child.transactionMeta.update\n\tstore.logger.info(\n\t\t`🛄`,\n\t\t`transaction`,\n\t\tchild.transactionMeta.update.key,\n\t\t`Applying transaction with ${updates.length} updates:`,\n\t\tupdates,\n\t)\n\n\tingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent)\n\n\tif (isRootStore(parent)) {\n\t\tsetEpochNumberOfAction(\n\t\t\tparent,\n\t\t\tchild.transactionMeta.update.key,\n\t\t\tchild.transactionMeta.update.epoch,\n\t\t)\n\t\tconst myTransaction = withdraw<F>(store, {\n\t\t\tkey: child.transactionMeta.update.key,\n\t\t\ttype: `transaction`,\n\t\t})\n\t\tmyTransaction?.subject.next(child.transactionMeta.update)\n\t\tstore.logger.info(\n\t\t\t`🛬`,\n\t\t\t`transaction`,\n\t\t\tchild.transactionMeta.update.key,\n\t\t\t`Finished applying transaction.`,\n\t\t)\n\t} else if (isChildStore(parent)) {\n\t\tparent.transactionMeta.update.updates.push(child.transactionMeta.update)\n\t}\n\tparent.on.transactionApplying.next(null)\n}\n","import type { Store } from \"../store\"\nimport { isRootStore } from \"./is-root-store\"\n\nexport function assignTransactionToContinuity(\n\tstore: Store,\n\tcontinuityKey: string,\n\ttransactionKey: string,\n): void {\n\tconst isRoot = isRootStore(store)\n\tif (!isRoot) {\n\t\treturn\n\t}\n\tconst { epoch, actionContinuities } = store.transactionMeta\n\tactionContinuities.set(continuityKey, transactionKey)\n\tif (!epoch.has(continuityKey)) {\n\t\tepoch.set(continuityKey, -1)\n\t}\n}\n","import type { Store } from \"./store\"\n\nexport type EnvironmentData = {\n\tstore: Store\n}\n\nexport function getEnvironmentData(store: Store): EnvironmentData {\n\treturn {\n\t\tstore,\n\t}\n}\n","export class LazyMap<K, V> extends Map<K, V> {\n\tpublic deleted: Set<K> = new Set()\n\tprotected readonly source: Map<K, V>\n\n\tpublic constructor(source: Map<K, V>) {\n\t\tsuper()\n\t\tthis.source = source\n\t}\n\n\tpublic get(key: K): V | undefined {\n\t\tconst has = super.has(key)\n\t\tif (has) {\n\t\t\treturn super.get(key)\n\t\t}\n\t\tif (!this.deleted.has(key) && this.source.has(key)) {\n\t\t\tconst value = this.source.get(key)\n\t\t\treturn value\n\t\t}\n\t\treturn undefined\n\t}\n\n\tpublic set(key: K, value: V): this {\n\t\tthis.deleted.delete(key)\n\t\treturn super.set(key, value)\n\t}\n\n\tpublic hasOwn(key: K): boolean {\n\t\treturn super.has(key)\n\t}\n\n\tpublic has(key: K): boolean {\n\t\treturn !this.deleted.has(key) && (super.has(key) || this.source.has(key))\n\t}\n\n\tpublic delete(key: K): boolean {\n\t\tthis.deleted.add(key)\n\t\treturn super.delete(key)\n\t}\n}\n","import type {\n\tdisposeState,\n\tfindState,\n\tgetState,\n\tresetState,\n\tsetState,\n} from \"atom.io\"\n\nimport { arbitrary } from \"../arbitrary\"\nimport { disposeFromStore, findInStore } from \"../families\"\nimport { getEnvironmentData } from \"../get-environment-data\"\nimport { getFromStore } from \"../get-state\"\nimport { Junction } from \"../junction\"\nimport { LazyMap } from \"../lazy-map\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { resetInStore, setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport type { Func } from \"../utility-types\"\nimport type { TransactionProgress } from \".\"\nimport { actUponStore, getEpochNumberOfAction } from \".\"\nimport type { ChildStore, RootStore } from \"./is-root-store\"\n\nexport const buildTransaction = (\n\tstore: Store,\n\tkey: string,\n\tparams: any[],\n\tid: string,\n): ChildStore => {\n\tconst parent = newest(store) as ChildStore | RootStore\n\tconst childBase: Omit<ChildStore, `transactionMeta`> = {\n\t\tparent,\n\t\tchild: null,\n\t\ton: parent.on,\n\t\tloggers: parent.loggers,\n\t\tlogger: parent.logger,\n\t\tconfig: parent.config,\n\t\tatoms: new LazyMap(parent.atoms),\n\t\tatomsThatAreDefault: new Set(parent.atomsThatAreDefault),\n\t\tfamilies: new LazyMap(parent.families),\n\t\tjoins: new LazyMap(parent.joins),\n\t\toperation: { open: false },\n\t\treadonlySelectors: new LazyMap(parent.readonlySelectors),\n\t\ttimelines: new LazyMap(parent.timelines),\n\t\ttimelineTopics: new Junction(parent.timelineTopics.toJSON()),\n\t\ttrackers: new Map(),\n\t\ttransactions: new LazyMap(parent.transactions),\n\t\tselectorAtoms: new Junction(parent.selectorAtoms.toJSON()),\n\t\tselectorGraph: new Junction(parent.selectorGraph.toJSON(), {\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t}),\n\t\twritableSelectors: new LazyMap(parent.writableSelectors),\n\t\tvalueMap: new LazyMap(parent.valueMap),\n\t\tdefaults: parent.defaults,\n\t\tdisposalTraces: store.disposalTraces.copy(),\n\t\tmolecules: new LazyMap(parent.molecules),\n\t\tmoleculeGraph: new Junction(parent.moleculeGraph.toJSON(), {\n\t\t\tmakeContentKey: parent.moleculeGraph.makeContentKey,\n\t\t}),\n\t\tmoleculeData: new Junction(parent.moleculeData.toJSON(), {\n\t\t\tmakeContentKey: parent.moleculeData.makeContentKey,\n\t\t}),\n\t\tmoleculeJoins: new Junction(parent.moleculeJoins.toJSON(), {\n\t\t\tmakeContentKey: parent.moleculeJoins.makeContentKey,\n\t\t}),\n\t\tmiscResources: new LazyMap(parent.miscResources),\n\t}\n\tconst epoch = getEpochNumberOfAction(store, key)\n\tconst transactionMeta: TransactionProgress<Func> = {\n\t\tphase: `building`,\n\t\tupdate: {\n\t\t\ttype: `transaction_update`,\n\t\t\tkey,\n\t\t\tid,\n\t\t\tepoch: epoch === undefined ? Number.NaN : epoch + 1,\n\t\t\tupdates: [],\n\t\t\tparams,\n\t\t\toutput: undefined,\n\t\t},\n\t\ttoolkit: {\n\t\t\tget: ((...ps: Parameters<typeof getState>) =>\n\t\t\t\tgetFromStore(child, ...ps)) as typeof getState,\n\t\t\tset: ((...ps: Parameters<typeof setState>) => {\n\t\t\t\tsetIntoStore(child, ...ps)\n\t\t\t}) as typeof setState,\n\t\t\treset: ((...ps: Parameters<typeof resetState>) => {\n\t\t\t\tresetInStore(child, ...ps)\n\t\t\t}) as typeof resetState,\n\t\t\trun: (token, identifier = arbitrary()) =>\n\t\t\t\tactUponStore(child, token, identifier),\n\t\t\tfind: ((...ps: Parameters<typeof findState>) =>\n\t\t\t\tfindInStore(store, ...ps)) as typeof findState,\n\t\t\tjson: (token) => getJsonToken(child, token),\n\t\t\tdispose: ((...ps: Parameters<typeof disposeState>) => {\n\t\t\t\tdisposeFromStore(child, ...ps)\n\t\t\t}) as typeof disposeState,\n\t\t\tenv: () => getEnvironmentData(child),\n\t\t},\n\t}\n\tconst child: ChildStore = Object.assign(childBase, {\n\t\ttransactionMeta,\n\t})\n\tparent.child = child\n\tstore.logger.info(\n\t\t`🛫`,\n\t\t`transaction`,\n\t\tkey,\n\t\t`Building transaction with params:`,\n\t\tparams,\n\t)\n\treturn child\n}\n","import type {\n\tTransactionOptions,\n\tTransactionToken,\n\tTransactionUpdate,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { Func } from \"../utility-types\"\nimport { abortTransaction } from \"./abort-transaction\"\nimport { applyTransaction } from \"./apply-transaction\"\nimport { buildTransaction } from \"./build-transaction\"\n\nexport type Transaction<F extends Func> = {\n\tkey: string\n\ttype: `transaction`\n\tinstall: (store: Store) => void\n\tsubject: Subject<TransactionUpdate<F>>\n\trun: (parameters: Parameters<F>, id?: string) => ReturnType<F>\n}\n\nexport function createTransaction<F extends Func>(\n\tstore: Store,\n\toptions: TransactionOptions<F>,\n): TransactionToken<F> {\n\tconst { key } = options\n\tconst transactionAlreadyExists = store.transactions.has(key)\n\tconst newTransaction: Transaction<F> = {\n\t\tkey,\n\t\ttype: `transaction`,\n\t\trun: (params: Parameters<F>, id: string) => {\n\t\t\tconst childStore = buildTransaction(store, key, params, id)\n\t\t\ttry {\n\t\t\t\tconst target = newest(store)\n\t\t\t\tconst { toolkit } = childStore.transactionMeta\n\t\t\t\tconst output = options.do(toolkit, ...params)\n\t\t\t\tapplyTransaction(output, target)\n\t\t\t\treturn output\n\t\t\t} catch (thrown) {\n\t\t\t\tabortTransaction(target)\n\t\t\t\tstore.logger.warn(`💥`, `transaction`, key, `caught:`, thrown)\n\t\t\t\tthrow thrown\n\t\t\t}\n\t\t},\n\t\tinstall: (s) => createTransaction(s, options),\n\t\tsubject: new Subject(),\n\t}\n\tconst target = newest(store)\n\ttarget.transactions.set(key, newTransaction)\n\tconst token = deposit(newTransaction)\n\tif (!transactionAlreadyExists) {\n\t\tstore.on.transactionCreation.next(token)\n\t}\n\treturn token\n}\n","import type { ActorToolkit, TransactionUpdate } from \"atom.io\"\n\nimport type { Junction } from \"../junction\"\nimport type { Func } from \"../utility-types\"\n\nexport * from \"./abort-transaction\"\nexport * from \"./act-upon-store\"\nexport * from \"./apply-transaction\"\nexport * from \"./assign-transaction-to-continuity\"\nexport * from \"./build-transaction\"\nexport * from \"./create-transaction\"\nexport * from \"./get-epoch-number\"\nexport * from \"./is-root-store\"\nexport * from \"./set-epoch-number\"\n\nexport const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const\nexport type TransactionPhase = (typeof TRANSACTION_PHASES)[number]\n\nexport type TransactionProgress<F extends Func> = {\n\tphase: `applying` | `building`\n\tupdate: TransactionUpdate<F>\n\ttoolkit: ActorToolkit\n}\n\nexport type TransactionEpoch = {\n\tepoch: Map<string, number>\n\tactionContinuities: Junction<`continuity`, string, `action`, string>\n}\n","import type {\n\tFamilyMetadata,\n\tWritableHeldSelectorOptions,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\n\nimport type { WritableHeldSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { markDone } from \"../operation\"\nimport { become } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { isRootStore } from \"../transaction\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createWritableHeldSelector = <T extends object>(\n\tstore: Store,\n\toptions: WritableHeldSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): WritableHeldSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst covered = new Set<string>()\n\tconst { key, const: constant } = options\n\tconst type = `writable_held_selector` as const\n\tconst setterToolkit = registerSelector(target, type, key, covered)\n\tconst { find, get, json } = setterToolkit\n\tconst getterToolkit = { find, get, json }\n\n\tconst getSelf = (getFn = options.get, innerTarget = newest(store)): T => {\n\t\tconst upstreamStates = innerTarget.selectorGraph.getRelationEntries({\n\t\t\tdownstreamSelectorKey: key,\n\t\t})\n\t\tfor (const [downstreamSelectorKey, { source }] of upstreamStates) {\n\t\t\tif (source !== key) {\n\t\t\t\tinnerTarget.selectorGraph.delete(downstreamSelectorKey, key)\n\t\t\t}\n\t\t}\n\t\tinnerTarget.selectorAtoms.delete(key)\n\t\tgetFn(getterToolkit, constant)\n\t\tcacheValue(innerTarget, key, constant, subject)\n\t\tstore.logger.info(`✨`, type, key, `=`, constant)\n\t\tcovered.clear()\n\t\treturn constant\n\t}\n\n\tconst setSelf = (next: T | ((oldValue: T) => T)): void => {\n\t\tconst innerTarget = newest(store)\n\t\tconst oldValue = getSelf(options.get, innerTarget)\n\t\tconst newValue = become(next)(oldValue)\n\t\tstore.logger.info(`📝`, type, key, `set (`, oldValue, `->`, newValue, `)`)\n\t\tcacheValue(innerTarget, key, newValue, subject)\n\t\tmarkDone(innerTarget, key)\n\t\tif (isRootStore(innerTarget)) {\n\t\t\tsubject.next({ newValue, oldValue })\n\t\t}\n\t\toptions.set(setterToolkit, newValue)\n\t}\n\tconst mySelector: WritableHeldSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritableHeldSelector(s, options, family),\n\t\tget: getSelf,\n\t\tset: setSelf,\n\t\t...(family && { family }),\n\t}\n\ttarget.writableSelectors.set(key, mySelector)\n\t// const initialValue = getSelf()\n\n\tconst token: WritableHeldSelectorToken<T> = { key, type }\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tWritablePureSelectorOptions,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\n\nimport type { WritablePureSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { markDone } from \"../operation\"\nimport { become } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { isRootStore } from \"../transaction\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createWritablePureSelector = <T>(\n\tstore: Store,\n\toptions: WritablePureSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): WritablePureSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst covered = new Set<string>()\n\tconst key = options.key\n\tconst type = `writable_pure_selector` as const\n\tconst setterToolkit = registerSelector(target, type, key, covered)\n\tconst { find, get, json } = setterToolkit\n\tconst getterToolkit = { find, get, json }\n\n\tconst getSelf = (getFn = options.get, innerTarget = newest(store)): T => {\n\t\tconst upstreamStates = innerTarget.selectorGraph.getRelationEntries({\n\t\t\tdownstreamSelectorKey: key,\n\t\t})\n\t\tfor (const [downstreamSelectorKey, { source }] of upstreamStates) {\n\t\t\tif (source !== key) {\n\t\t\t\tinnerTarget.selectorGraph.delete(downstreamSelectorKey, key)\n\t\t\t}\n\t\t}\n\t\tinnerTarget.selectorAtoms.delete(key)\n\t\tconst value = getFn(getterToolkit)\n\t\tconst cached = cacheValue(innerTarget, key, value, subject)\n\t\tstore.logger.info(`✨`, type, key, `=`, cached)\n\t\tcovered.clear()\n\t\treturn value\n\t}\n\n\tconst setSelf = (next: T | ((oldValue: T) => T)): void => {\n\t\tconst innerTarget = newest(store)\n\t\tconst oldValue = getSelf(options.get, innerTarget)\n\t\tconst newValue = become(next)(oldValue)\n\t\tstore.logger.info(`📝`, type, key, `set (`, oldValue, `->`, newValue, `)`)\n\t\tcacheValue(innerTarget, options.key, newValue, subject)\n\t\tmarkDone(innerTarget, options.key)\n\t\tif (isRootStore(innerTarget)) {\n\t\t\tsubject.next({ newValue, oldValue })\n\t\t}\n\t\toptions.set(setterToolkit, newValue)\n\t}\n\tconst mySelector: WritablePureSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritablePureSelector(s, options, family),\n\t\tget: getSelf,\n\t\tset: setSelf,\n\t\t...(family && { family }),\n\t}\n\ttarget.writableSelectors.set(key, mySelector)\n\tconst initialValue = getSelf()\n\tstore.logger.info(`✨`, mySelector.type, mySelector.key, `=`, initialValue)\n\tconst token: WritablePureSelectorToken<T> = {\n\t\tkey,\n\t\ttype,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\treturn token\n}\n","import type {\n\tReadonlyHeldSelectorOptions,\n\tReadonlyHeldSelectorToken,\n\tReadonlyPureSelectorOptions,\n\tReadonlyPureSelectorToken,\n\tWritableHeldSelectorOptions,\n\tWritableHeldSelectorToken,\n\tWritablePureSelectorOptions,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { createReadonlyHeldSelector } from \"./create-readonly-held-selector\"\nimport { createReadonlyPureSelector } from \"./create-readonly-pure-selector\"\nimport { createWritableHeldSelector } from \"./create-writable-held-selector\"\nimport { createWritablePureSelector } from \"./create-writable-pure-selector\"\n\nexport function createStandaloneSelector<T extends object>(\n\tstore: Store,\n\toptions: WritableHeldSelectorOptions<T>,\n): WritableHeldSelectorToken<T>\nexport function createStandaloneSelector<T extends object>(\n\tstore: Store,\n\toptions: ReadonlyHeldSelectorOptions<T>,\n): ReadonlyHeldSelectorToken<T>\nexport function createStandaloneSelector<T>(\n\tstore: Store,\n\toptions: WritablePureSelectorOptions<T>,\n): WritablePureSelectorToken<T>\nexport function createStandaloneSelector<T>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorOptions<T>,\n): ReadonlyPureSelectorToken<T>\nexport function createStandaloneSelector(\n\tstore: Store,\n\toptions:\n\t\t| ReadonlyHeldSelectorOptions<any>\n\t\t| ReadonlyPureSelectorOptions<any>\n\t\t| WritableHeldSelectorOptions<any>\n\t\t| WritablePureSelectorOptions<any>,\n):\n\t| ReadonlyHeldSelectorToken<any>\n\t| ReadonlyPureSelectorToken<any>\n\t| WritableHeldSelectorToken<any>\n\t| WritablePureSelectorToken<any> {\n\tconst isWritable = `set` in options\n\tconst isHeld = `const` in options\n\n\tif (isHeld && isWritable) {\n\t\tconst state = createWritableHeldSelector(store, options, undefined)\n\t\tstore.on.selectorCreation.next(state)\n\t\treturn state\n\t}\n\tif (isHeld) {\n\t\tconst state = createReadonlyHeldSelector(store, options, undefined)\n\t\tstore.on.selectorCreation.next(state)\n\t\treturn state\n\t}\n\tif (isWritable) {\n\t\tconst state = createWritablePureSelector(store, options, undefined)\n\t\tstore.on.selectorCreation.next(state)\n\t\treturn state\n\t}\n\tconst state = createReadonlyPureSelector(store, options, undefined)\n\tstore.on.selectorCreation.next(state)\n\treturn state\n}\n","import type { SelectorFamilyToken, SelectorToken } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { isChildStore, newest, withdraw } from \"..\"\n\nexport function disposeSelector(\n\tstore: Store,\n\tselectorToken: SelectorToken<unknown>,\n): void {\n\tconst target = newest(store)\n\tconst { key, type } = selectorToken\n\tconst selector = withdraw(target, selectorToken)\n\tif (!selector.family) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttype,\n\t\t\tkey,\n\t\t\t`Standalone selectors cannot be disposed.`,\n\t\t)\n\t} else {\n\t\tconst molecule = target.molecules.get(selector.family.subKey)\n\t\tif (molecule) {\n\t\t\ttarget.moleculeData.delete(selector.family.subKey, selector.family.key)\n\t\t}\n\t\tlet familyToken: SelectorFamilyToken<any, any>\n\t\tswitch (selectorToken.type) {\n\t\t\tcase `writable_held_selector`:\n\t\t\t\t{\n\t\t\t\t\ttarget.writableSelectors.delete(key)\n\t\t\t\t\tfamilyToken = {\n\t\t\t\t\t\tkey: selector.family.key,\n\t\t\t\t\t\ttype: `writable_held_selector_family`,\n\t\t\t\t\t}\n\t\t\t\t\tconst family = withdraw(store, familyToken)\n\t\t\t\t\tfamily.subject.next({\n\t\t\t\t\t\ttype: `state_disposal`,\n\t\t\t\t\t\tsubType: `selector`,\n\t\t\t\t\t\ttoken: selectorToken,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `writable_pure_selector`:\n\t\t\t\t{\n\t\t\t\t\ttarget.writableSelectors.delete(key)\n\t\t\t\t\tfamilyToken = {\n\t\t\t\t\t\tkey: selector.family.key,\n\t\t\t\t\t\ttype: `writable_pure_selector_family`,\n\t\t\t\t\t}\n\t\t\t\t\tconst family = withdraw(store, familyToken)\n\t\t\t\t\tfamily.subject.next({\n\t\t\t\t\t\ttype: `state_disposal`,\n\t\t\t\t\t\tsubType: `selector`,\n\t\t\t\t\t\ttoken: selectorToken,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `readonly_held_selector`:\n\t\t\t\t{\n\t\t\t\t\ttarget.readonlySelectors.delete(key)\n\t\t\t\t\tfamilyToken = {\n\t\t\t\t\t\tkey: selector.family.key,\n\t\t\t\t\t\ttype: `readonly_held_selector_family`,\n\t\t\t\t\t}\n\t\t\t\t\tconst family = withdraw(store, familyToken)\n\t\t\t\t\tfamily.subject.next({\n\t\t\t\t\t\ttype: `state_disposal`,\n\t\t\t\t\t\tsubType: `selector`,\n\t\t\t\t\t\ttoken: selectorToken,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `readonly_pure_selector`:\n\t\t\t\t{\n\t\t\t\t\ttarget.readonlySelectors.delete(key)\n\t\t\t\t\tfamilyToken = {\n\t\t\t\t\t\tkey: selector.family.key,\n\t\t\t\t\t\ttype: `readonly_pure_selector_family`,\n\t\t\t\t\t}\n\t\t\t\t\tconst family = withdraw(store, familyToken)\n\t\t\t\t\tfamily.subject.next({\n\t\t\t\t\t\ttype: `state_disposal`,\n\t\t\t\t\t\tsubType: `selector`,\n\t\t\t\t\t\ttoken: selectorToken,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\n\t\ttarget.valueMap.delete(key)\n\t\ttarget.selectorAtoms.delete(key)\n\t\ttarget.selectorGraph.delete(key)\n\t\tstore.logger.info(`🔥`, selectorToken.type, key, `deleted`)\n\t\tif (isChildStore(target) && target.transactionMeta.phase === `building`) {\n\t\t\ttarget.transactionMeta.update.updates.push({\n\t\t\t\ttype: `state_disposal`,\n\t\t\t\tsubType: `selector`,\n\t\t\t\ttoken: selectorToken,\n\t\t\t})\n\t\t} else {\n\t\t\tstore.on.selectorDisposal.next(selectorToken)\n\t\t}\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tfindState,\n\tgetState,\n\tReadonlyPureSelectorFamilyOptions,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tprettyPrintTokenType,\n\ttype ReadonlyPureSelectorFamily,\n} from \"..\"\nimport { newest } from \"../lineage\"\nimport { createReadonlyPureSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createReadonlyPureSelectorFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): ReadonlyPureSelectorFamilyToken<T, K> {\n\tconst familyKey = options.key\n\tconst type = `readonly_pure_selector_family`\n\n\tconst familyToken = {\n\t\tkey: familyKey,\n\t\ttype,\n\t} as const satisfies ReadonlyPureSelectorFamilyToken<T, K>\n\n\tconst existing = store.families.get(familyKey)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\ttype,\n\t\t\tfamilyKey,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\n\tconst subject = new Subject<\n\t\t| StateCreation<ReadonlyPureSelectorToken<T>>\n\t\t| StateDisposal<ReadonlyPureSelectorToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): ReadonlyPureSelectorToken<T> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst token = createReadonlyPureSelector(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\tkey: fullKey,\n\t\t\t\tget: options.get(key),\n\t\t\t},\n\t\t\tfamily,\n\t\t)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst readonlySelectorFamily = Object.assign(familyFunction, familyToken, {\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlyPureSelectorFamily(s, options),\n\t\tdefault: (key: K) => {\n\t\t\tconst getFn = options.get(key)\n\t\t\treturn getFn({\n\t\t\t\tget: ((...args: Parameters<typeof getState>) =>\n\t\t\t\t\tgetFromStore(store, ...args)) as typeof getState,\n\t\t\t\tfind: ((...args: Parameters<typeof findState>) =>\n\t\t\t\t\tfindInStore(store, ...args)) as typeof findState,\n\t\t\t\tjson: (token) => getJsonToken(store, token),\n\t\t\t})\n\t\t},\n\t}) satisfies ReadonlyPureSelectorFamily<T, K>\n\n\tstore.families.set(familyKey, readonlySelectorFamily)\n\treturn familyToken\n}\n","import type {\n\tFamilyMetadata,\n\tRegularAtomFamilyOptions,\n\tRegularAtomFamilyToken,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { prettyPrintTokenType, type RegularAtomFamily } from \"..\"\nimport { createRegularAtom } from \"../atom\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createRegularAtomFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: RegularAtomFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): RegularAtomFamilyToken<T, K> {\n\tconst familyToken = {\n\t\tkey: options.key,\n\t\ttype: `atom_family`,\n\t} as const satisfies RegularAtomFamilyToken<T, K>\n\n\tconst existing = store.families.get(options.key)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\t`atom_family`,\n\t\t\toptions.key,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\n\tconst subject = new Subject<\n\t\tStateCreation<RegularAtomToken<T>> | StateDisposal<RegularAtomToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): RegularAtomToken<any> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\tconst fullKey = `${options.key}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst def = options.default\n\t\tconst individualOptions: RegularAtomOptions<T> = {\n\t\t\tkey: fullKey,\n\t\t\tdefault: def instanceof Function ? () => def(key) : def,\n\t\t}\n\t\tif (options.effects) {\n\t\t\tindividualOptions.effects = options.effects(key)\n\t\t}\n\n\t\tconst token = createRegularAtom(target, individualOptions, family)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst atomFamily = Object.assign(familyFunction, familyToken, {\n\t\tsubject,\n\t\tinstall: (s: Store) => createRegularAtomFamily(s, options),\n\t\tinternalRoles,\n\t}) satisfies RegularAtomFamily<T, K>\n\n\tstore.families.set(options.key, atomFamily)\n\tstore.defaults.set(options.key, options.default)\n\treturn familyToken\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyHeldSelectorFamilyOptions,\n\tReadonlyHeldSelectorFamilyToken,\n\tReadonlyHeldSelectorToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ReadonlyHeldSelectorFamily } from \"..\"\nimport { prettyPrintTokenType } from \"..\"\nimport { newest } from \"../lineage\"\nimport { createReadonlyHeldSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createReadonlyHeldSelectorFamily<\n\tT extends object,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\toptions: ReadonlyHeldSelectorFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): ReadonlyHeldSelectorFamilyToken<T, K> {\n\tconst familyKey = options.key\n\tconst type = `readonly_held_selector_family`\n\n\tconst familyToken = {\n\t\tkey: familyKey,\n\t\ttype,\n\t} as const satisfies ReadonlyHeldSelectorFamilyToken<T, K>\n\n\tconst existing = store.families.get(familyKey)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\ttype,\n\t\t\tfamilyKey,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\n\tconst subject = new Subject<\n\t\t| StateCreation<ReadonlyHeldSelectorToken<T>>\n\t\t| StateDisposal<ReadonlyHeldSelectorToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): ReadonlyHeldSelectorToken<T> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst token = createReadonlyHeldSelector(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\tkey: fullKey,\n\t\t\t\tconst: options.const(key),\n\t\t\t\tget: options.get(key),\n\t\t\t},\n\t\t\tfamily,\n\t\t)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst readonlySelectorFamily = Object.assign(familyFunction, familyToken, {\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlyHeldSelectorFamily(s, options),\n\t\tdefault: options.const,\n\t}) satisfies ReadonlyHeldSelectorFamily<T, K>\n\n\tstore.families.set(familyKey, readonlySelectorFamily)\n\treturn familyToken\n}\n","import type {\n\tFamilyMetadata,\n\tStateCreation,\n\tStateDisposal,\n\tWritableHeldSelectorFamilyOptions,\n\tWritableHeldSelectorFamilyToken,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { prettyPrintTokenType, type WritableHeldSelectorFamily } from \"..\"\nimport { newest } from \"../lineage\"\nimport { createWritableHeldSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createWritableHeldSelectorFamily<\n\tT extends object,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\toptions: WritableHeldSelectorFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): WritableHeldSelectorFamilyToken<T, K> {\n\tconst familyKey = options.key\n\tconst type = `writable_held_selector_family`\n\n\tconst familyToken = {\n\t\tkey: familyKey,\n\t\ttype,\n\t} as const satisfies WritableHeldSelectorFamilyToken<T, K>\n\n\tconst existing = store.families.get(familyKey)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\ttype,\n\t\t\tfamilyKey,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\tconst subject = new Subject<\n\t\t| StateCreation<WritableHeldSelectorToken<T>>\n\t\t| StateDisposal<WritableHeldSelectorToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): WritableHeldSelectorToken<T> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst token = createWritableHeldSelector(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\tkey: fullKey,\n\t\t\t\tconst: options.const(key),\n\t\t\t\tget: options.get(key),\n\t\t\t\tset: options.set(key),\n\t\t\t},\n\t\t\tfamily,\n\t\t)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst selectorFamily = Object.assign(familyFunction, familyToken, {\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritableHeldSelectorFamily(s, options),\n\t\tdefault: options.const,\n\t}) satisfies WritableHeldSelectorFamily<T, K>\n\n\tstore.families.set(familyKey, selectorFamily)\n\treturn familyToken\n}\n","import type {\n\tFamilyMetadata,\n\tfindState,\n\tgetState,\n\tStateCreation,\n\tStateDisposal,\n\tWritablePureSelectorFamilyOptions,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tprettyPrintTokenType,\n\ttype WritablePureSelectorFamily,\n} from \"..\"\nimport { newest } from \"../lineage\"\nimport { createWritablePureSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createWritablePureSelectorFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: WritablePureSelectorFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): WritablePureSelectorFamilyToken<T, K> {\n\tconst familyKey = options.key\n\tconst type = `writable_pure_selector_family`\n\n\tconst familyToken = {\n\t\tkey: familyKey,\n\t\ttype,\n\t} as const satisfies WritablePureSelectorFamilyToken<T, K>\n\n\tconst existing = store.families.get(familyKey)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\ttype,\n\t\t\tfamilyKey,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\tconst subject = new Subject<\n\t\t| StateCreation<WritablePureSelectorToken<T>>\n\t\t| StateDisposal<WritablePureSelectorToken<T>>\n\t>()\n\n\tconst familyFunction = (key: K): WritablePureSelectorToken<T> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst token = createWritablePureSelector(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\tkey: fullKey,\n\t\t\t\tget: options.get(key),\n\t\t\t\tset: options.set(key),\n\t\t\t},\n\t\t\tfamily,\n\t\t)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst selectorFamily = Object.assign(familyFunction, familyToken, {\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritablePureSelectorFamily(s, options),\n\t\tdefault: (key: K) => {\n\t\t\tconst getFn = options.get(key)\n\t\t\treturn getFn({\n\t\t\t\tget: ((...args: Parameters<typeof getState>) =>\n\t\t\t\t\tgetFromStore(store, ...args)) as typeof getState,\n\t\t\t\tfind: ((...args: Parameters<typeof findState>) =>\n\t\t\t\t\tfindInStore(store, ...args)) as typeof findState,\n\t\t\t\tjson: (token) => getJsonToken(store, token),\n\t\t\t})\n\t\t},\n\t}) satisfies WritablePureSelectorFamily<T, K>\n\n\tstore.families.set(familyKey, selectorFamily)\n\treturn familyToken\n}\n","import type {\n\tReadonlyHeldSelectorFamilyOptions,\n\tReadonlyHeldSelectorFamilyToken,\n\tReadonlyPureSelectorFamilyOptions,\n\tReadonlyPureSelectorFamilyToken,\n\tSelectorFamilyToken,\n\tWritableHeldSelectorFamilyOptions,\n\tWritableHeldSelectorFamilyToken,\n\tWritablePureSelectorFamilyOptions,\n\tWritablePureSelectorFamilyToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { createReadonlyHeldSelectorFamily } from \"./create-readonly-held-selector-family\"\nimport { createReadonlyPureSelectorFamily } from \"./create-readonly-pure-selector-family\"\nimport { createWritableHeldSelectorFamily } from \"./create-writable-held-selector-family\"\nimport { createWritablePureSelectorFamily } from \"./create-writable-pure-selector-family\"\n\nexport function createSelectorFamily<T extends object, K extends Canonical>(\n\tstore: Store,\n\toptions: WritableHeldSelectorFamilyOptions<T, K>,\n): WritableHeldSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T extends object, K extends Canonical>(\n\tstore: Store,\n\toptions: ReadonlyHeldSelectorFamilyOptions<T, K>,\n): ReadonlyHeldSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: WritablePureSelectorFamilyOptions<T, K>,\n): WritablePureSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T, K extends Canonical>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorFamilyOptions<T, K>,\n): ReadonlyPureSelectorFamilyToken<T, K>\nexport function createSelectorFamily(\n\tstore: Store,\n\toptions:\n\t\t| ReadonlyHeldSelectorFamilyOptions<any, any>\n\t\t| ReadonlyPureSelectorFamilyOptions<any, any>\n\t\t| WritableHeldSelectorFamilyOptions<any, any>\n\t\t| WritablePureSelectorFamilyOptions<any, any>,\n): SelectorFamilyToken<any, any> {\n\tconst isWritable = `set` in options\n\tconst isHeld = `const` in options\n\n\tif (isHeld && isWritable) {\n\t\treturn createWritableHeldSelectorFamily(store, options, undefined)\n\t}\n\tif (isHeld) {\n\t\treturn createReadonlyHeldSelectorFamily(store, options, undefined)\n\t}\n\tif (isWritable) {\n\t\treturn createWritablePureSelectorFamily(store, options)\n\t}\n\treturn createReadonlyPureSelectorFamily(store, options)\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport { NotFoundError } from \"../not-found-error\"\nimport type { Store } from \"../store\"\nimport { isChildStore, isRootStore } from \"../transaction\"\n\nexport function initFamilyMemberInStore<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, J, K>,\n\tkey: Key,\n): MutableAtomToken<T, J, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n): AtomToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritablePureSelectorToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n): SelectorToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T, K>\n\nexport function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T, K>\n\nexport function initFamilyMemberInStore(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n): ReadableToken<any> {\n\tconst family = store.families.get(token.key)\n\tif (family === undefined) {\n\t\tthrow new NotFoundError(token, store)\n\t}\n\tconst state = family(key)\n\tconst target = newest(store)\n\tif (state.family) {\n\t\tif (isRootStore(target)) {\n\t\t\tswitch (state.type) {\n\t\t\t\tcase `atom`:\n\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\tstore.on.atomCreation.next(state)\n\t\t\t\t\tbreak\n\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\tcase `readonly_pure_selector`:\n\t\t\t\tcase `writable_held_selector`:\n\t\t\t\tcase `readonly_held_selector`:\n\t\t\t\t\tstore.on.selectorCreation.next(state)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t} else if (\n\t\t\tisChildStore(target) &&\n\t\t\ttarget.on.transactionApplying.state === null\n\t\t) {\n\t\t\ttarget.transactionMeta.update.updates.push({\n\t\t\t\ttype: `state_creation`,\n\t\t\t\ttoken: state,\n\t\t\t})\n\t\t}\n\t}\n\treturn state\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { Molecule, ReadableState } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport { deposit, type Store } from \"../store\"\n\nexport function seekInStore<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, J, K>,\n\tkey: Key,\n): MutableAtomToken<T, J, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n): AtomToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritablePureSelectorToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n): SelectorToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T, K> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T, K> | undefined\n\nexport function seekInStore(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n): ReadableToken<any> | undefined {\n\tconst subKey = stringifyJson(key)\n\tconst fullKey = `${token.key}(${subKey})`\n\tconst target = newest(store)\n\tlet state: Molecule<any> | ReadableState<any> | undefined\n\tswitch (token.type) {\n\t\tcase `atom_family`:\n\t\tcase `mutable_atom_family`:\n\t\t\tstate = target.atoms.get(fullKey)\n\t\t\tbreak\n\t\tcase `writable_held_selector_family`:\n\t\tcase `writable_pure_selector_family`:\n\t\t\tstate = target.writableSelectors.get(fullKey)\n\t\t\tbreak\n\t\tcase `readonly_held_selector_family`:\n\t\tcase `readonly_pure_selector_family`:\n\t\t\tstate = target.readonlySelectors.get(fullKey)\n\t\t\tbreak\n\t}\n\tif (state) {\n\t\treturn deposit(state)\n\t}\n\treturn state\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport { type Canonical, type Json, stringifyJson } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport { counterfeit, type Store } from \"../store\"\nimport { initFamilyMemberInStore } from \"./init-family-member\"\nimport { seekInStore } from \"./seek-in-store\"\n\nexport function findInStore<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, J, K>,\n\tkey: Key,\n): MutableAtomToken<T, J, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n): AtomToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritablePureSelectorToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n): SelectorToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T, K>\n\nexport function findInStore(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n): ReadableToken<any> {\n\tlet state = seekInStore(store, token, key)\n\tif (state) {\n\t\treturn state\n\t}\n\tconst stringKey = stringifyJson(key)\n\tconst molecule = store.molecules.get(stringKey)\n\tif (!molecule && store.config.lifespan === `immortal`) {\n\t\tconst fakeToken = counterfeit(token, key)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\tfakeToken.type,\n\t\t\tfakeToken.key,\n\t\t\t`was not found in store \"${store.config.name}\"; returned a counterfeit token.`,\n\t\t)\n\t\treturn fakeToken\n\t}\n\tstate = initFamilyMemberInStore(store, token, key)\n\tif (molecule) {\n\t\tconst target = newest(store)\n\t\ttarget.moleculeData.set(stringKey, token.key)\n\t}\n\treturn state\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { disposeAtom } from \"../atom\"\nimport { disposeSelector } from \"../selector\"\nimport { type Store, withdraw } from \"../store\"\nimport { findInStore } from \"./find-in-store\"\n\nexport function disposeFromStore(store: Store, token: ReadableToken<any>): void\n\nexport function disposeFromStore<K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, K>,\n\tkey: K,\n): void\n\nexport function disposeFromStore(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<any, any>, key: Canonical]\n\t\t| [token: ReadableToken<any>]\n): void {\n\tlet token: ReadableToken<any>\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t} else {\n\t\tconst family = params[0]\n\t\tconst key = params[1]\n\t\tconst maybeToken = findInStore(store, family, key)\n\t\ttoken = maybeToken\n\t}\n\ttry {\n\t\twithdraw(store, token)\n\t} catch (_) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`could not be disposed because it was not found in the store \"${store.config.name}\".`,\n\t\t)\n\t\treturn\n\t}\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tdisposeAtom(store, token)\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\tcase `readonly_held_selector`:\n\t\t\tdisposeSelector(store, token)\n\t\t\tbreak\n\t}\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { readOrComputeValue } from \"./read-or-compute-value\"\n\nexport function getFromStore<T>(store: Store, token: ReadableToken<T>): T\n\nexport function getFromStore<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: K,\n): T\n\nexport function getFromStore(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<any, any>, key: Canonical]\n\t\t| [token: ReadableToken<any>]\n): any {\n\tlet token: ReadableToken<any>\n\tlet family: ReadableFamilyToken<any, Canonical> | null\n\tlet key: Canonical | null\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\ttoken = findInStore(store, family, key)\n\t}\n\tif (`counterfeit` in token && `family` in token) {\n\t\t// biome-ignore lint/style/noNonNullAssertion: family must be present\n\t\tfamily = store.families.get(token.family.key)!\n\t\tconst subKey = token.family.subKey\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === subKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`could not be retrieved because it was not found in the store \"${store.config.name}\".`,\n\t\t\tdisposal\n\t\t\t\t? `This state was previously disposed:\\n${disposal.trace}`\n\t\t\t\t: `No previous disposal trace was found.`,\n\t\t)\n\t\tswitch (family.type) {\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\tcase `readonly_pure_selector_family`:\n\t\t\tcase `writable_pure_selector_family`:\n\t\t\tcase `readonly_held_selector_family`:\n\t\t\tcase `writable_held_selector_family`: {\n\t\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\t\treturn store.defaults.get(token.family.key)\n\t\t\t\t}\n\t\t\t\t3\n\t\t\t\tconst defaultValue = withdraw(store, family).default(subKey)\n\t\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\t\treturn defaultValue\n\t\t\t}\n\t\t}\n\t}\n\n\treturn readOrComputeValue(store, withdraw(store, token))\n}\n","import type { ReadableToken, StateUpdate, UpdateHandler } from \"atom.io\"\n\nimport { readOrComputeValue } from \"../get-state\"\nimport { traceRootSelectorAtoms } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { subscribeToRootDependency } from \"./subscribe-to-root-atoms\"\n\nexport function subscribeToState<T>(\n\tstore: Store,\n\ttoken: ReadableToken<T>,\n\tkey: string,\n\thandleUpdate: UpdateHandler<T>,\n): () => void {\n\tfunction safelyHandleUpdate(update: StateUpdate<any>): void {\n\t\tif (store.operation.open) {\n\t\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t\t`state subscription ${key}`,\n\t\t\t\t() => {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\thandleUpdate(update)\n\t\t\t\t},\n\t\t\t)\n\t\t} else {\n\t\t\thandleUpdate(update)\n\t\t}\n\t}\n\tconst state = withdraw(store, token)\n\tstore.logger.info(`👀`, state.type, state.key, `Adding subscription \"${key}\"`)\n\tconst isSelector =\n\t\tstate.type === `writable_pure_selector` ||\n\t\tstate.type === `readonly_pure_selector`\n\tconst rootSubs = new Map<string, () => void>()\n\tlet updateHandler: UpdateHandler<T> = safelyHandleUpdate\n\tif (isSelector) {\n\t\treadOrComputeValue(store, state)\n\t\tfor (const [atomKey, atom] of traceRootSelectorAtoms(store, state.key)) {\n\t\t\trootSubs.set(atomKey, subscribeToRootDependency(store, state, atom))\n\t\t}\n\t\tupdateHandler = function updateRootsBeforeHandlingUpdate(update) {\n\t\t\tconst dependencies = traceRootSelectorAtoms(store, state.key)\n\t\t\tfor (const [previousRootKey, unsub] of rootSubs) {\n\t\t\t\tconst currentRoot = dependencies.get(previousRootKey)\n\t\t\t\tif (currentRoot) {\n\t\t\t\t\tdependencies.delete(previousRootKey)\n\t\t\t\t} else {\n\t\t\t\t\tunsub()\n\t\t\t\t\trootSubs.delete(previousRootKey)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [atomKey, atom] of dependencies) {\n\t\t\t\trootSubs.set(atomKey, subscribeToRootDependency(store, state, atom))\n\t\t\t}\n\t\t\tsafelyHandleUpdate(update)\n\t\t}\n\t}\n\tconst mainUnsubFunction = state.subject.subscribe(key, updateHandler)\n\tconst unsubscribe = () => {\n\t\tstore.logger.info(\n\t\t\t`🙈`,\n\t\t\tstate.type,\n\t\t\tstate.key,\n\t\t\t`Removing subscription \"${key}\"`,\n\t\t)\n\t\tmainUnsubFunction()\n\t\tfor (const unsubFromDependency of rootSubs.values()) {\n\t\t\tunsubFromDependency()\n\t\t}\n\t}\n\n\treturn unsubscribe\n}\n","import type { TimelineManageable, TimelineToken, TimelineUpdate } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { withdraw } from \"..\"\n\nexport const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(\n\tstore: Store,\n\ttoken: TimelineToken<ManagedAtom>,\n\tkey: string,\n\thandleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void,\n): (() => void) => {\n\tconst tl = withdraw(store, token)\n\tstore.logger.info(`👀`, `timeline`, token.key, `Adding subscription \"${key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(\n\t\t\t`🙈`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Removing subscription \"${key}\" from timeline`,\n\t\t)\n\t\tunsubscribe()\n\t}\n}\n","import type { TransactionToken, TransactionUpdateHandler } from \"atom.io\"\n\nimport type { Func, Store } from \"..\"\nimport { withdraw } from \"..\"\n\nexport const subscribeToTransaction = <F extends Func>(\n\tstore: Store,\n\ttoken: TransactionToken<F>,\n\tkey: string,\n\thandleUpdate: TransactionUpdateHandler<F>,\n): (() => void) => {\n\tconst tx = withdraw(store, token)\n\tstore.logger.info(\n\t\t`👀`,\n\t\t`transaction`,\n\t\ttoken.key,\n\t\t`Adding subscription \"${key}\"`,\n\t)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(\n\t\t\t`🙈`,\n\t\t\t`transaction`,\n\t\t\ttoken.key,\n\t\t\t`Removing subscription \"${key}\"`,\n\t\t)\n\t\tunsubscribe()\n\t}\n}\n","import type { FamilyMetadata, MutableAtomToken, RegularAtomToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"..\"\nimport {\n\tgetFromStore,\n\tnewest,\n\tsetIntoStore,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n} from \"..\"\nimport { createRegularAtom } from \"../atom\"\nimport { isChildStore } from \"../transaction/is-root-store\"\nimport type { Transceiver } from \"./transceiver\"\n\n/**\n * @internal Give the tracker a transceiver state and a store, and it will\n * subscribe to the transceiver's inner value. When the inner value changes,\n * the tracker will update its own state to reflect the change.\n */\nexport class Tracker<Mutable extends Transceiver<any>> {\n\tprivate initializeState(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store,\n\t): RegularAtomToken<\n\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t> {\n\t\tconst latestUpdateStateKey = `*${mutableState.key}`\n\t\tstore.atoms.delete(latestUpdateStateKey)\n\t\tstore.valueMap.delete(latestUpdateStateKey)\n\t\tconst familyMetaData: FamilyMetadata | undefined = mutableState.family\n\t\t\t? {\n\t\t\t\t\tkey: `*${mutableState.family.key}`,\n\t\t\t\t\tsubKey: mutableState.family.subKey,\n\t\t\t\t}\n\t\t\t: undefined\n\t\tconst latestUpdateState = createRegularAtom<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: latestUpdateStateKey,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\tfamilyMetaData,\n\t\t)\n\t\tif (store.parent?.valueMap.has(latestUpdateStateKey)) {\n\t\t\tconst parentValue = store.parent.valueMap.get(latestUpdateStateKey)\n\t\t\tstore.valueMap.set(latestUpdateStateKey, parentValue)\n\t\t}\n\n\t\treturn latestUpdateState\n\t}\n\n\tprivate unsubscribeFromInnerValue!: () => void\n\tprivate unsubscribeFromState!: () => void\n\tprivate observeCore(\n\t\tmutableState: MutableAtomToken<Mutable, any>,\n\t\tlatestUpdateState: RegularAtomToken<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst subscriptionKey = `tracker:${target.config.name}:${\n\t\t\tisChildStore(target) ? target.transactionMeta.update.key : `main`\n\t\t}:${mutableState.key}`\n\t\tconst originalInnerValue = getFromStore(target, mutableState)\n\t\tthis.unsubscribeFromInnerValue = originalInnerValue.subscribe(\n\t\t\tsubscriptionKey,\n\t\t\t(update) => {\n\t\t\t\tsetIntoStore(target, latestUpdateState, update)\n\t\t\t},\n\t\t)\n\t\tthis.unsubscribeFromState = subscribeToState(\n\t\t\ttarget,\n\t\t\tmutableState,\n\t\t\tsubscriptionKey,\n\t\t\t(update) => {\n\t\t\t\tif (update.newValue !== update.oldValue) {\n\t\t\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\t\t\tthis.unsubscribeFromInnerValue = update.newValue.subscribe(\n\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\t(transceiverUpdate) => {\n\t\t\t\t\t\t\tsetIntoStore(target, latestUpdateState, transceiverUpdate)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n\n\tprivate updateCore<Core extends Transceiver<any>>(\n\t\tmutableState: MutableAtomToken<Core, Json.Serializable>,\n\t\tlatestUpdateState: RegularAtomToken<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst subscriptionKey = `tracker:${target.config.name}:${\n\t\t\tisChildStore(target) ? target.transactionMeta.update.key : `main`\n\t\t}:${mutableState.key}`\n\t\tsubscribeToState(\n\t\t\ttarget,\n\t\t\tlatestUpdateState,\n\t\t\tsubscriptionKey,\n\t\t\t({ newValue, oldValue }) => {\n\t\t\t\tconst timelineId = target.timelineTopics.getRelatedKey(\n\t\t\t\t\tlatestUpdateState.key,\n\t\t\t\t)\n\n\t\t\t\tif (timelineId) {\n\t\t\t\t\tconst timelineData = target.timelines.get(timelineId)\n\t\t\t\t\tif (timelineData?.timeTraveling) {\n\t\t\t\t\t\tconst unsubscribe = subscribeToTimeline(\n\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t{ key: timelineId, type: `timeline` },\n\t\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\tsetIntoStore(target, mutableState, (transceiver) => {\n\t\t\t\t\t\t\t\t\tif (update === `redo` && newValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.do(newValue)\n\t\t\t\t\t\t\t\t\t} else if (update === `undo` && oldValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.undo(oldValue)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn transceiver\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = target.on.operationClose.subscribe(\n\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\tconst mutable = getFromStore(target, mutableState)\n\t\t\t\t\t\tconst updateNumber =\n\t\t\t\t\t\t\tnewValue === null ? -1 : mutable.getUpdateNumber(newValue)\n\t\t\t\t\t\tconst eventOffset = updateNumber - mutable.cacheUpdateNumber\n\t\t\t\t\t\tif (newValue && eventOffset === 1) {\n\t\t\t\t\t\t\tsetIntoStore(\n\t\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t\tmutableState,\n\t\t\t\t\t\t\t\t(transceiver) => (transceiver.do(newValue), transceiver),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ttarget.logger.info(\n\t\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t\t`mutable_atom`,\n\t\t\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t\t\t`could not be updated. Expected update number ${\n\t\t\t\t\t\t\t\t\tmutable.cacheUpdateNumber + 1\n\t\t\t\t\t\t\t\t}, but got ${updateNumber}`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t},\n\t\t)\n\t}\n\n\tpublic mutableState: MutableAtomToken<Mutable, Json.Serializable>\n\tpublic latestUpdateState: RegularAtomToken<\n\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t>\n\n\tpublic [Symbol.dispose]!: () => void\n\n\tpublic constructor(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store,\n\t) {\n\t\tthis.mutableState = mutableState\n\t\tconst target = newest(store)\n\t\tthis.latestUpdateState = this.initializeState(mutableState, target)\n\t\tthis.observeCore(mutableState, this.latestUpdateState, target)\n\t\tthis.updateCore(mutableState, this.latestUpdateState, target)\n\t\ttarget.trackers.set(mutableState.key, this)\n\t\tthis[Symbol.dispose] = () => {\n\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\tthis.unsubscribeFromState()\n\t\t\ttarget.trackers.delete(mutableState.key)\n\t\t}\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJson } from \"atom.io/json\"\n\nimport type { MutableAtom } from \"..\"\nimport { resetInStore, setIntoStore } from \"..\"\nimport { newest } from \"../lineage\"\nimport { deposit, type Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtom<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(\n\tstore: Store,\n\toptions: MutableAtomOptions<T, J>,\n\tfamily: FamilyMetadata | undefined,\n): MutableAtomToken<T, J> {\n\tstore.logger.info(\n\t\t`🔨`,\n\t\t`atom`,\n\t\toptions.key,\n\t\t`creating in store \"${store.config.name}\"`,\n\t)\n\tconst target = newest(store)\n\tconst { key } = options\n\tconst existing = target.atoms.get(key)\n\tconst type = `mutable_atom`\n\tif (existing && existing.type === type) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttype,\n\t\t\tkey,\n\t\t\t`Tried to create atom, but it already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: MutableAtom<T, J> = {\n\t\t...options,\n\t\ttype,\n\t\tinstall: (s: Store) => {\n\t\t\ts.logger.info(`🛠️`, `atom`, key, `installing in store \"${s.config.name}\"`)\n\t\t\treturn createMutableAtom(s, options, family)\n\t\t},\n\t\tsubject,\n\t} as const\n\tif (family) {\n\t\tnewAtom.family = family\n\t}\n\ttarget.atoms.set(newAtom.key, newAtom)\n\tconst token = deposit(newAtom)\n\tif (options.effects) {\n\t\tlet effectIndex = 0\n\t\tconst cleanupFunctions: (() => void)[] = []\n\t\tfor (const effect of options.effects) {\n\t\t\tconst cleanup = effect({\n\t\t\t\tresetSelf: () => {\n\t\t\t\t\tresetInStore(store, token)\n\t\t\t\t},\n\t\t\t\tsetSelf: (next) => {\n\t\t\t\t\tsetIntoStore(store, token, next)\n\t\t\t\t},\n\t\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\t\tsubscribeToState(store, token, `effect[${effectIndex}]`, handle),\n\t\t\t})\n\t\t\tif (cleanup) {\n\t\t\t\tcleanupFunctions.push(cleanup)\n\t\t\t}\n\t\t\t++effectIndex\n\t\t}\n\t\tnewAtom.cleanup = () => {\n\t\t\tfor (const cleanup of cleanupFunctions) {\n\t\t\t\tcleanup()\n\t\t\t}\n\t\t}\n\t}\n\n\tnew Tracker(token, store)\n\tif (!family) {\n\t\tselectJson(token, options, store)\n\t}\n\tstore.on.atomCreation.next(token)\n\treturn token\n}\n","import type { Canonical } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport type { MutableAtomFamily, RegularAtomFamily } from \"..\"\nimport { createRegularAtomFamily } from \"../families\"\nimport { type Store, withdraw } from \"../store\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport class FamilyTracker<\n\tCore extends Transceiver<any>,\n\tFamilyMemberKey extends Canonical,\n> {\n\tprivate trackers: Map<FamilyMemberKey, Tracker<Core>> = new Map()\n\n\tpublic readonly latestUpdateAtoms: RegularAtomFamily<\n\t\t(Core extends Transceiver<infer Signal> ? Signal : never) | null,\n\t\tFamilyMemberKey\n\t>\n\tpublic readonly mutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>\n\n\tpublic constructor(\n\t\tmutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>,\n\t\tstore: Store,\n\t) {\n\t\tconst updateAtoms = createRegularAtomFamily<\n\t\t\t(Core extends Transceiver<infer Signal> ? Signal : never) | null,\n\t\t\tFamilyMemberKey\n\t\t>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `*${mutableAtoms.key}`,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\t[`mutable`, `updates`],\n\t\t)\n\t\tthis.latestUpdateAtoms = withdraw(store, updateAtoms)\n\t\tthis.mutableAtoms = mutableAtoms\n\t\tthis.mutableAtoms.subject.subscribe(\n\t\t\t`store=${store.config.name}::tracker-atom-family`,\n\t\t\t(event) => {\n\t\t\t\tconst { type, token } = event\n\t\t\t\tif (token.family) {\n\t\t\t\t\tconst key = parseJson(token.family.subKey)\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase `state_creation`:\n\t\t\t\t\t\t\tthis.trackers.set(key, new Tracker<Core>(token, store))\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase `state_disposal`:\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tconst tracker = this.trackers.get(key)\n\t\t\t\t\t\t\t\tif (tracker) {\n\t\t\t\t\t\t\t\t\ttracker[Symbol.dispose]()\n\t\t\t\t\t\t\t\t\tthis.trackers.delete(key)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tMutableAtomFamilyOptions,\n\tMutableAtomFamilyToken,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tStateCreation,\n\tStateDisposal,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { selectJsonFamily, stringifyJson } from \"atom.io/json\"\n\nimport { type MutableAtomFamily, prettyPrintTokenType } from \"..\"\nimport { newest } from \"../lineage\"\nimport { createMutableAtom } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { FamilyTracker } from \"./tracker-family\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\toptions: MutableAtomFamilyOptions<T, J, K>,\n\tinternalRoles?: string[],\n): MutableAtomFamilyToken<T, J, K> {\n\tconst familyToken = {\n\t\tkey: options.key,\n\t\ttype: `mutable_atom_family`,\n\t} as const satisfies MutableAtomFamilyToken<T, J, K>\n\n\tconst existing = store.families.get(options.key)\n\tif (existing) {\n\t\tstore.logger.error(\n\t\t\t`❗`,\n\t\t\t`mutable_atom_family`,\n\t\t\toptions.key,\n\t\t\t`Overwriting an existing ${prettyPrintTokenType(\n\t\t\t\texisting,\n\t\t\t)} \"${existing.key}\" in store \"${store.config.name}\". You can safely ignore this warning if it is due to hot module replacement.`,\n\t\t)\n\t}\n\n\tconst subject = new Subject<\n\t\tStateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>\n\t>()\n\n\tconst familyFunction = (key: K): MutableAtomToken<T, J> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\tconst fullKey = `${options.key}(${subKey})`\n\t\tconst target = newest(store)\n\n\t\tconst individualOptions: MutableAtomOptions<T, J> = {\n\t\t\tkey: fullKey,\n\t\t\tdefault: () => options.default(key),\n\t\t\ttoJson: options.toJson,\n\t\t\tfromJson: options.fromJson,\n\t\t}\n\t\tif (options.effects) {\n\t\t\tindividualOptions.effects = options.effects(key)\n\t\t}\n\n\t\tconst token = createMutableAtom(target, individualOptions, family)\n\n\t\tsubject.next({ type: `state_creation`, token })\n\t\treturn token\n\t}\n\n\tconst atomFamily = Object.assign(familyFunction, familyToken, {\n\t\tsubject,\n\t\tinstall: (s: Store) => createMutableAtomFamily(s, options),\n\t\ttoJson: options.toJson,\n\t\tfromJson: options.fromJson,\n\t\tinternalRoles,\n\t}) satisfies MutableAtomFamily<T, J, K>\n\n\tstore.families.set(options.key, atomFamily)\n\tselectJsonFamily(store, atomFamily, options)\n\tnew FamilyTracker(atomFamily, store)\n\treturn familyToken\n}\n","import type { MutableAtomFamilyToken } from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport type { WritablePureSelectorFamily } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonFamily = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Canonical,\n>(\n\tmutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>,\n\tstore: Store,\n): WritablePureSelectorFamily<SerializableCore, Key> => {\n\tconst target = newest(store)\n\tconst key = `${mutableAtomFamily.key}:JSON`\n\tconst jsonFamily: WritablePureSelectorFamily<SerializableCore, Key> =\n\t\ttarget.families.get(key) as WritablePureSelectorFamily<SerializableCore, Key>\n\treturn jsonFamily\n}\n","import type {\n\tMutableAtomToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { newest } from \"../lineage\"\nimport { type Store, withdraw } from \"../store\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonToken = <\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tstore: Store,\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): WritablePureSelectorToken<SerializableCore> => {\n\tif (mutableAtomToken.family) {\n\t\tconst target = newest(store)\n\t\tconst jsonFamilyKey = `${mutableAtomToken.family.key}:JSON`\n\t\tconst jsonFamilyToken: WritablePureSelectorFamilyToken<\n\t\t\tSerializableCore,\n\t\t\tstring\n\t\t> = {\n\t\t\tkey: jsonFamilyKey,\n\t\t\ttype: `writable_pure_selector_family`,\n\t\t}\n\t\tconst family = withdraw(target, jsonFamilyToken)\n\t\tconst subKey = JSON.parse(mutableAtomToken.family.subKey)\n\t\tconst jsonToken = findInStore(store, family, subKey)\n\t\treturn jsonToken\n\t}\n\tconst token: WritablePureSelectorToken<SerializableCore> = {\n\t\ttype: `writable_pure_selector`,\n\t\tkey: `${mutableAtomToken.key}:JSON`,\n\t}\n\treturn token\n}\n","import type { MutableAtomFamilyToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { AtomFamily } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport type { Signal, Transceiver } from \"./transceiver\"\n\nexport const getUpdateFamily = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends string,\n>(\n\tmutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>,\n\tstore: Store,\n): AtomFamily<Signal<Core>, Key> => {\n\tconst target = newest(store)\n\tconst key = `*${mutableAtomFamily.key}`\n\tconst updateFamily: AtomFamily<Signal<Core>, Key> = target.families.get(\n\t\tkey,\n\t) as AtomFamily<Signal<Core>, Key>\n\treturn updateFamily\n}\n","import type { MutableAtomToken, RegularAtomToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Signal, Transceiver } from \"./transceiver\"\n\nexport const getUpdateToken = <\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): RegularAtomToken<Signal<Core>> => {\n\tconst key = `*${mutableAtomToken.key}`\n\tconst updateToken: RegularAtomToken<Signal<Core>> = { type: `atom`, key }\n\tif (mutableAtomToken.family) {\n\t\tupdateToken.family = {\n\t\t\tkey: `*${mutableAtomToken.family.key}`,\n\t\t\tsubKey: mutableAtomToken.family.subKey,\n\t\t}\n\t}\n\treturn updateToken\n}\n","import type { Json } from \"atom.io/json\"\n\nexport interface Transceiver<S extends Json.Serializable> {\n\tdo: (update: S) => number | `OUT_OF_RANGE` | null\n\tundo: (update: S) => void\n\tsubscribe: (key: string, fn: (update: S) => void) => () => void\n\tcacheUpdateNumber: number\n\tgetUpdateNumber: (update: S) => number\n}\n\nexport function isTransceiver(\n\tvalue: unknown,\n): value is Transceiver<Json.Serializable> {\n\treturn (\n\t\ttypeof value === `object` &&\n\t\tvalue !== null &&\n\t\t`do` in value &&\n\t\t`undo` in value &&\n\t\t`subscribe` in value\n\t)\n}\n\nexport type TransceiverMode = `playback` | `record` | `transaction`\n\nexport type Signal<TVR extends Transceiver<any>> = TVR extends Transceiver<\n\tinfer S\n>\n\t? S\n\t: never\n\n/*\nA transceiver may also keep a list of updates that have been applied to it.\nThis is useful for undo/redo functionality, especially in the context of\nrevising history. It is a good idea to accept a cache limit in your \nconstructor, and overwrite old updates. Here's an example of how we \nmight set that up:\n\nmyTransceiver = Transceiver {\n\tcacheUpdateNumber: number = 27\n\tcacheIdx: number = 1\n\tcacheLimit: number = 3\n\tcache: Array<Update> = [\n\t\t26=add:\"x\"\n\t\t27=del:\"x\" (current)\n\t\t25=add:\"y\"\n\t]\n}\n\nCONFIRM/NO-OP\nUpdate `27=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 27, update = `del:\"x\"`]\t\n- updateOffset = updateNumber - cacheUpdateNumber // 0\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // 1\n- update === cache.get(eventIdx) // true\n- return null // 👍\n\nEXPECTED UPDATE\nUpdate `28=add:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 28, update = `add:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 1\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // true (we're ready to apply this update)\n- cacheIdx += eventOffset // 2\n- cacheIdx %= cacheLimit // 2\n- cache[cacheIdx] = update // cache = <{ 0 => add:\"x\" }>\n- return null // 👍\n\nUNEXPECTED UPDATE\nUpdate `29=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 29, update = `del:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 2\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // false (we're NOT ready to apply this update)\n- updateIdx := cacheIdx + updateOffset // 3\n- updateIdx %= cacheLimit // 0\n- cache[updateIdx] = update // cache = <{ 0 => del:\"x\" }> \n- expectedUpdateNumber = cacheUpdateNumber + 1 // 28\n- return expectedUpdateNumber // 🤨👂\n\nSUCCESSFUL ROLLBACK UPDATE\nUpdate `25=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 25, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -2\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // -1\n- eventIdx %= cacheLimit // 2\n- update === cache[eventIdx] // false (we're rolling back)\n- done := false\n- update := cache[cacheIdx] // update = `del:\"x\"`\n- undo(update) // myTransceiver.undo(`del:\"x\"`)\n- while (!done) {\n- \tcacheIdx -= 1 // 0, -1\n- \tcacheIdx %= cacheLimit // 0, 2\n- \tupdate = cache[cacheIdx] // update = `add:\"y\"`, `add:\"x\"`\n- \tundo(update) // myTransceiver.undo(`add:\"y\"`), myTransceiver.undo(`add:\"x\"`)\n- \tdone = cacheIdx === eventIdx // false, true\n- }\n- do(update) // myTransceiver.do(`add:\"z\"`)\n- return null // 👍\n\nUNSUCCESSFUL ROLLBACK UPDATE\nUpdate `24=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 24, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -3\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // 3 < 3 // false (we don't remember this update)\n- return `OUT_OF_RANGE` // 😵‍💫👂\n\n*/\n","import type {\n\tAtomToken,\n\tLogger,\n\tMoleculeCreation,\n\tMoleculeDisposal,\n\tSelectorToken,\n\tTimelineToken,\n\tTransactionToken,\n} from \"atom.io\"\nimport { AtomIOLogger } from \"atom.io\"\nimport type { Canonical, stringified } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tHeldSelectorFamily,\n\tMutableAtomFamily,\n\tPureSelectorFamily,\n\tReadonlySelector,\n\tRegularAtomFamily,\n\tWritableSelector,\n} from \"..\"\nimport { isReservedIntrospectionKey } from \"..\"\nimport type { Join } from \"../join\"\nimport { Junction } from \"../junction\"\nimport type { Lineage } from \"../lineage\"\nimport type { Molecule } from \"../molecule\"\nimport type { Tracker, Transceiver } from \"../mutable\"\nimport { getJsonToken, getUpdateToken } from \"../mutable\"\nimport type { OperationProgress } from \"../operation\"\nimport { StatefulSubject, Subject } from \"../subject\"\nimport type { Timeline } from \"../timeline\"\nimport type {\n\tTransaction,\n\tTransactionEpoch,\n\tTransactionProgress,\n} from \"../transaction\"\nimport { isRootStore } from \"../transaction\"\nimport type { Func } from \"../utility-types\"\nimport { CircularBuffer } from \"./circular-buffer\"\n\nexport class Store implements Lineage {\n\tpublic parent: Store | null = null\n\tpublic child: Store | null = null\n\n\tpublic valueMap: Map<string, any> = new Map()\n\tpublic defaults: Map<string, any> = new Map()\n\n\tpublic atoms: Map<string, Atom<any>> = new Map()\n\tpublic writableSelectors: Map<string, WritableSelector<any>> = new Map()\n\tpublic readonlySelectors: Map<string, ReadonlySelector<any>> = new Map()\n\n\tpublic atomsThatAreDefault: Set<string> = new Set()\n\tpublic selectorAtoms: Junction<`selectorKey`, string, `atomKey`, string> =\n\t\tnew Junction({\n\t\t\tbetween: [`selectorKey`, `atomKey`],\n\t\t\tcardinality: `n:n`,\n\t\t})\n\tpublic selectorGraph: Junction<\n\t\t`upstreamSelectorKey`,\n\t\tstring,\n\t\t`downstreamSelectorKey`,\n\t\tstring,\n\t\t{ source: string }\n\t> = new Junction(\n\t\t{\n\t\t\tbetween: [`upstreamSelectorKey`, `downstreamSelectorKey`],\n\t\t\tcardinality: `n:n`,\n\t\t},\n\t\t{\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t},\n\t)\n\tpublic trackers: Map<string, Tracker<Transceiver<any>>> = new Map()\n\tpublic families: Map<\n\t\tstring,\n\t\t| HeldSelectorFamily<any, any>\n\t\t| MutableAtomFamily<any, any, any>\n\t\t| PureSelectorFamily<any, any>\n\t\t| RegularAtomFamily<any, any>\n\t> = new Map()\n\tpublic joins: Map<string, Join<any, any, any, any, any, any>> = new Map()\n\n\tpublic transactions: Map<string, Transaction<Func>> = new Map()\n\tpublic transactionMeta: TransactionEpoch | TransactionProgress<Func> = {\n\t\tepoch: new Map<string, number>(),\n\t\tactionContinuities: new Junction({\n\t\t\tbetween: [`continuity`, `action`],\n\t\t\tcardinality: `1:n`,\n\t\t}),\n\t}\n\n\tpublic timelines: Map<string, Timeline<any>> = new Map()\n\tpublic timelineTopics: Junction<\n\t\t`timelineKey`,\n\t\tstring,\n\t\t`topicKey`,\n\t\tstring,\n\t\t{ topicType: `atom_family` | `atom` | `molecule_family` | `molecule` }\n\t> = new Junction({\n\t\tbetween: [`timelineKey`, `topicKey`],\n\t\tcardinality: `1:n`,\n\t})\n\n\tpublic disposalTraces: CircularBuffer<{ key: string; trace: string }> =\n\t\tnew CircularBuffer(100)\n\n\tpublic molecules: Map<string, Molecule<Canonical>> = new Map()\n\tpublic moleculeJoins: Junction<\n\t\t`moleculeKey`,\n\t\tstringified<Canonical>,\n\t\t`joinKey`,\n\t\tstring\n\t> = new Junction(\n\t\t{\n\t\t\tbetween: [`moleculeKey`, `joinKey`],\n\t\t\tcardinality: `n:n`,\n\t\t},\n\t\t{\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t},\n\t)\n\tpublic moleculeGraph: Junction<\n\t\t`upstreamMoleculeKey`,\n\t\tstringified<Canonical> | `root`,\n\t\t`downstreamMoleculeKey`,\n\t\tstringified<Canonical>,\n\t\t{ source: stringified<Canonical> }\n\t> = new Junction(\n\t\t{\n\t\t\tbetween: [`upstreamMoleculeKey`, `downstreamMoleculeKey`],\n\t\t\tcardinality: `n:n`,\n\t\t},\n\t\t{\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t},\n\t)\n\tpublic moleculeData: Junction<\n\t\t`moleculeKey`,\n\t\tstringified<Canonical>,\n\t\t`stateFamilyKey`,\n\t\tstring\n\t> = new Junction(\n\t\t{\n\t\t\tbetween: [`moleculeKey`, `stateFamilyKey`],\n\t\t\tcardinality: `n:n`,\n\t\t},\n\t\t{\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t},\n\t)\n\tpublic miscResources: Map<string, Disposable> = new Map()\n\n\tpublic on: StoreEventCarrier = {\n\t\tatomCreation: new Subject(),\n\t\tatomDisposal: new Subject(),\n\t\tselectorCreation: new Subject(),\n\t\tselectorDisposal: new Subject(),\n\t\ttimelineCreation: new Subject(),\n\t\ttransactionCreation: new Subject(),\n\t\ttransactionApplying: new StatefulSubject(null),\n\t\toperationClose: new Subject(),\n\t\tmoleculeCreation: new Subject(),\n\t\tmoleculeDisposal: new Subject(),\n\t}\n\tpublic operation: OperationProgress = { open: false }\n\n\tpublic config: {\n\t\tname: string\n\t\tlifespan: `ephemeral` | `immortal`\n\t} = {\n\t\tname: `IMPLICIT_STORE`,\n\t\tlifespan: `ephemeral`,\n\t}\n\n\tpublic loggers: AtomIOLogger[] = [\n\t\tnew AtomIOLogger(`warn`, (_, __, key) => !isReservedIntrospectionKey(key)),\n\t]\n\tpublic logger: Logger = {\n\t\terror: (...messages) => {\n\t\t\tfor (const logger of this.loggers) logger.error(...messages)\n\t\t},\n\t\tinfo: (...messages) => {\n\t\t\tfor (const logger of this.loggers) logger.info(...messages)\n\t\t},\n\t\twarn: (...messages) => {\n\t\t\tfor (const logger of this.loggers) logger.warn(...messages)\n\t\t},\n\t}\n\n\tpublic constructor(config: Store[`config`], store: Store | null = null) {\n\t\tthis.config = {\n\t\t\t...store?.config,\n\t\t\t...config,\n\t\t}\n\t\tif (store !== null) {\n\t\t\tthis.operation = { ...store?.operation }\n\t\t\tif (isRootStore(store)) {\n\t\t\t\tthis.transactionMeta = {\n\t\t\t\t\tepoch: new Map(store?.transactionMeta.epoch),\n\t\t\t\t\tactionContinuities: new Junction(\n\t\t\t\t\t\tstore?.transactionMeta.actionContinuities.toJSON(),\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const [, family] of store.families) {\n\t\t\t\tif (\n\t\t\t\t\tfamily.internalRoles?.includes(`mutable`) ||\n\t\t\t\t\tfamily.internalRoles?.includes(`join`)\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfamily.install(this)\n\t\t\t}\n\t\t\tconst mutableHelpers = new Set<string>()\n\t\t\tfor (const [, atom] of store.atoms) {\n\t\t\t\tif (mutableHelpers.has(atom.key)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tatom.install(this)\n\t\t\t\tif (atom.type === `mutable_atom`) {\n\t\t\t\t\tconst originalJsonToken = getJsonToken(store, atom)\n\t\t\t\t\tconst originalUpdateToken = getUpdateToken(atom)\n\t\t\t\t\tmutableHelpers.add(originalJsonToken.key)\n\t\t\t\t\tmutableHelpers.add(originalUpdateToken.key)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [, selector] of store.readonlySelectors) {\n\t\t\t\tselector.install(this)\n\t\t\t}\n\t\t\tfor (const [, selector] of store.writableSelectors) {\n\t\t\t\tif (mutableHelpers.has(selector.key)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tselector.install(this)\n\t\t\t}\n\t\t\tfor (const [, tx] of store.transactions) {\n\t\t\t\ttx.install(this)\n\t\t\t}\n\t\t\tfor (const [, timeline] of store.timelines) {\n\t\t\t\ttimeline.install(this)\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport type StoreEventCarrier = {\n\tatomCreation: Subject<AtomToken<unknown>>\n\tatomDisposal: Subject<AtomToken<unknown>>\n\tselectorCreation: Subject<SelectorToken<unknown>>\n\tselectorDisposal: Subject<SelectorToken<unknown>>\n\ttimelineCreation: Subject<TimelineToken<unknown>>\n\ttransactionCreation: Subject<TransactionToken<Func>>\n\ttransactionApplying: StatefulSubject<TransactionProgress<Func> | null>\n\toperationClose: Subject<OperationProgress>\n\tmoleculeCreation: Subject<MoleculeCreation>\n\tmoleculeDisposal: Subject<MoleculeDisposal>\n}\n\ndeclare global {\n\tvar ATOM_IO_IMPLICIT_STORE: Store | undefined\n}\n\nexport const IMPLICIT: { readonly STORE: Store } = {\n\tget STORE(): Store {\n\t\tglobalThis.ATOM_IO_IMPLICIT_STORE ??= new Store({\n\t\t\tname: `IMPLICIT_STORE`,\n\t\t\tlifespan: `ephemeral`,\n\t\t})\n\t\treturn globalThis.ATOM_IO_IMPLICIT_STORE\n\t},\n}\n\nexport const clearStore = (store: Store): void => {\n\tconst { config } = store\n\tfor (const disposable of store.miscResources.values()) {\n\t\tdisposable[Symbol.dispose]()\n\t}\n\tObject.assign(store, new Store(config))\n\tstore.config = config\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomIOToken,\n\tAtomToken,\n\tHeldSelectorFamilyToken,\n\tHeldSelectorToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tPureSelectorFamilyToken,\n\tPureSelectorToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyHeldSelectorFamilyToken,\n\tReadonlyHeldSelectorToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tReadonlySelectorFamilyToken,\n\tReadonlySelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableFamilyToken,\n\tWritableHeldSelectorFamilyToken,\n\tWritableHeldSelectorToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableSelectorFamilyToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical, Json } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tFunc,\n\tHeldSelector,\n\tHeldSelectorFamily,\n\tMutableAtom,\n\tMutableAtomFamily,\n\tPureSelector,\n\tPureSelectorFamily,\n\tReadableFamily,\n\tReadableState,\n\tReadonlyHeldSelector,\n\tReadonlyHeldSelectorFamily,\n\tReadonlyPureSelector,\n\tReadonlyPureSelectorFamily,\n\tReadonlySelector,\n\tReadonlySelectorFamily,\n\tRegularAtom,\n\tRegularAtomFamily,\n\tSelector,\n\tSelectorFamily,\n\tTransceiver,\n\tWritableFamily,\n\tWritableHeldSelector,\n\tWritableHeldSelectorFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableSelector,\n\tWritableSelectorFamily,\n\tWritableState,\n} from \"..\"\nimport { NotFoundError } from \"..\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Store } from \"./store\"\n\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T>,\n): RegularAtom<T>\nexport function withdraw<T extends Transceiver<any>>(\n\tstore: Store,\n\ttoken: MutableAtomToken<T, any>,\n): MutableAtom<T, any>\nexport function withdraw<T>(store: Store, token: AtomToken<T>): Atom<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritableHeldSelectorToken<T>,\n): WritableHeldSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadonlyHeldSelectorToken<T>,\n): ReadonlyHeldSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T>,\n): WritablePureSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T>,\n): ReadonlyPureSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadonlySelectorToken<T>,\n): ReadonlySelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritableSelectorToken<T>,\n): WritableSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: HeldSelectorToken<T>,\n): HeldSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: PureSelectorToken<T>,\n): PureSelector<T>\nexport function withdraw<T>(store: Store, token: SelectorToken<T>): Selector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritableToken<T>,\n): WritableState<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadableToken<T>,\n): ReadableState<T>\n\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K>,\n): RegularAtomFamily<T, K>\nexport function withdraw<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, J, K>,\n): MutableAtomFamily<T, J, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K>,\n): AtomFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlyHeldSelectorFamilyToken<T, K>,\n): ReadonlyHeldSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableHeldSelectorFamilyToken<T, K>,\n): WritableHeldSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n): ReadonlyPureSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n): WritablePureSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlySelectorFamilyToken<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableSelectorFamilyToken<T, K>,\n): WritableSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: HeldSelectorFamilyToken<T, K>,\n): HeldSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: PureSelectorFamilyToken<T, K>,\n): PureSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K>,\n): SelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K>,\n): ReadableFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n): WritableFamily<T, K>\n\nexport function withdraw<T extends Func>(\n\tstore: Store,\n\ttoken: TransactionToken<T>,\n): Transaction<T extends Func ? T : never>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: TimelineToken<T>,\n): Timeline<T extends TimelineManageable ? T : never>\n\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritableToken<T>,\n): WritableState<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadableToken<T>,\n): ReadableState<T>\n\nexport function withdraw(\n\tstore: Store,\n\ttoken: AtomIOToken,\n): AtomIOInternalResource\n\nexport function withdraw(\n\tstore: Store,\n\ttoken: AtomIOToken,\n): AtomIOInternalResource {\n\tlet withdrawn: AtomIOInternalResource | undefined\n\tlet target: Store | null = store\n\twhile (target !== null) {\n\t\tswitch (token.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\twithdrawn = target.atoms.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `writable_pure_selector`:\n\t\t\tcase `writable_held_selector`:\n\t\t\t\twithdrawn = target.writableSelectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `readonly_pure_selector`:\n\t\t\tcase `readonly_held_selector`:\n\t\t\t\twithdrawn = target.readonlySelectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\tcase `writable_pure_selector_family`:\n\t\t\tcase `readonly_pure_selector_family`:\n\t\t\tcase `writable_held_selector_family`:\n\t\t\tcase `readonly_held_selector_family`:\n\t\t\t\twithdrawn = target.families.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `timeline`:\n\t\t\t\twithdrawn = target.timelines.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `transaction`:\n\t\t\t\twithdrawn = target.transactions.get(token.key)\n\t\t\t\tbreak\n\t\t}\n\t\tif (withdrawn) {\n\t\t\treturn withdrawn\n\t\t}\n\t\ttarget = target.child\n\t}\n\tthrow new NotFoundError(token, store)\n}\n","import type {\n\tFamilyMetadata,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\n\nimport { type RegularAtom, resetInStore, setIntoStore } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\n\nexport function createRegularAtom<T>(\n\tstore: Store,\n\toptions: RegularAtomOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): RegularAtomToken<T> {\n\tconst type = `atom`\n\tconst { key } = options\n\tstore.logger.info(\n\t\t`🔨`,\n\t\t`atom`,\n\t\tkey,\n\t\t`creating in store \"${store.config.name}\"`,\n\t)\n\tconst target = newest(store)\n\tconst existing = target.atoms.get(key)\n\tif (existing && existing.type === type) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`atom`,\n\t\t\tkey,\n\t\t\t`Tried to create atom, but it already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: RegularAtom<T> = {\n\t\t...options,\n\t\ttype,\n\t\tinstall: (s: Store) => {\n\t\t\ts.logger.info(`🛠️`, type, key, `installing in store \"${s.config.name}\"`)\n\t\t\treturn createRegularAtom(s, options, family)\n\t\t},\n\t\tsubject,\n\t} as const\n\tif (family) {\n\t\tnewAtom.family = family\n\t}\n\t// let initialValue = def\n\t// if (def instanceof Function) {\n\t// \tinitialValue = def()\n\t// }\n\ttarget.atoms.set(key, newAtom)\n\t// cacheValue(target, key, initialValue, subject)\n\tconst token = deposit(newAtom)\n\tif (options.effects) {\n\t\tlet effectIndex = 0\n\t\tconst cleanupFunctions: (() => void)[] = []\n\t\tfor (const effect of options.effects) {\n\t\t\tconst cleanup = effect({\n\t\t\t\tresetSelf: () => {\n\t\t\t\t\tresetInStore(store, token)\n\t\t\t\t},\n\t\t\t\tsetSelf: (next) => {\n\t\t\t\t\tsetIntoStore(store, token, next)\n\t\t\t\t},\n\t\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\t\tsubscribeToState(store, token, `effect[${effectIndex}]`, handle),\n\t\t\t})\n\t\t\tif (cleanup) {\n\t\t\t\tcleanupFunctions.push(cleanup)\n\t\t\t}\n\t\t\t++effectIndex\n\t\t}\n\t\tnewAtom.cleanup = () => {\n\t\t\tfor (const cleanup of cleanupFunctions) {\n\t\t\t\tcleanup()\n\t\t\t}\n\t\t}\n\t}\n\tstore.on.atomCreation.next(token)\n\treturn token\n}\n","import type { AtomDisposal, AtomToken } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { getUpdateToken, isChildStore, newest, withdraw } from \"..\"\n\nexport function disposeAtom(store: Store, atomToken: AtomToken<unknown>): void {\n\tconst target = newest(store)\n\tconst { key, family } = atomToken\n\tconst atom = withdraw(target, atomToken)\n\tif (!family) {\n\t\tstore.logger.error(`❌`, `atom`, key, `Standalone atoms cannot be disposed.`)\n\t} else {\n\t\tatom.cleanup?.()\n\t\tconst lastValue = store.valueMap.get(atom.key)\n\t\tconst atomFamily = withdraw(store, { key: family.key, type: `atom_family` })\n\n\t\tconst disposal: AtomDisposal<AtomToken<unknown>> = {\n\t\t\ttype: `state_disposal`,\n\t\t\tsubType: `atom`,\n\t\t\ttoken: atomToken,\n\t\t\tvalue: lastValue,\n\t\t}\n\n\t\tatomFamily.subject.next(disposal)\n\n\t\tconst isChild = isChildStore(target)\n\n\t\ttarget.atoms.delete(key)\n\t\ttarget.valueMap.delete(key)\n\t\ttarget.selectorAtoms.delete(key)\n\t\ttarget.atomsThatAreDefault.delete(key)\n\t\tstore.timelineTopics.delete(key)\n\n\t\tif (atomToken.type === `mutable_atom`) {\n\t\t\tconst updateToken = getUpdateToken(atomToken)\n\t\t\tdisposeAtom(store, updateToken)\n\t\t\tstore.trackers.delete(key)\n\t\t}\n\t\tstore.logger.info(`🔥`, `atom`, key, `deleted`)\n\t\tif (isChild && target.transactionMeta.phase === `building`) {\n\t\t\tconst mostRecentUpdate = target.transactionMeta.update.updates.at(-1)\n\t\t\tconst wasMoleculeDisposal = mostRecentUpdate?.type === `molecule_disposal`\n\t\t\tconst updateAlreadyCaptured =\n\t\t\t\twasMoleculeDisposal &&\n\t\t\t\tmostRecentUpdate.values.some(([k]) => k === atom.family?.key)\n\n\t\t\tif (!updateAlreadyCaptured) {\n\t\t\t\ttarget.transactionMeta.update.updates.push(disposal)\n\t\t\t}\n\t\t} else {\n\t\t\tstore.on.atomDisposal.next(atomToken)\n\t\t}\n\t}\n}\n","import type { AtomIOToken } from \"atom.io\"\n\nimport { newest } from \"./lineage\"\nimport { type Store, withdraw } from \"./store\"\nimport { isChildStore } from \"./transaction\"\n\n/**\n * @public\n * Install the given tokens into the target store\n * @param tokens - States, families, transactions, and timelines to install into the target store\n * @param target - The store to install the tokens into\n * @param source - The store to install the tokens from\n *\n */\nexport function installIntoStore(\n\ttokens: AtomIOToken[],\n\ttarget: Store,\n\tsource: Store,\n): void {\n\tconst sourceNewest = newest(source)\n\tif (isChildStore(sourceNewest)) {\n\t\tsource.logger.error(\n\t\t\t`❌`,\n\t\t\t`transaction`,\n\t\t\tsourceNewest.transactionMeta.update.key,\n\t\t\t`could not install the following tokens into store \"${target.config.name} from \"${source.config.name}\":`,\n\t\t\ttokens,\n\t\t\t`${sourceNewest.config.name} is undergoing a transaction.`,\n\t\t)\n\t\treturn\n\t}\n\tconst targetNewest = newest(target)\n\tif (isChildStore(targetNewest)) {\n\t\ttarget.logger.error(\n\t\t\t`❌`,\n\t\t\t`transaction`,\n\t\t\ttargetNewest.transactionMeta.update.key,\n\t\t\t`could not install the following tokens into store \"${target.config.name} from \"${source.config.name}\":`,\n\t\t\ttokens,\n\t\t\t`${targetNewest.config.name} is undergoing a transaction.`,\n\t\t)\n\t\treturn\n\t}\n\tfor (const token of tokens) {\n\t\tconst resource = withdraw(source, token)\n\t\tresource.install(target)\n\t}\n}\n","import type { JoinOptions, JoinToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { Join } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function createJoin<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object,\n>(\n\tstore: Store,\n\toptions: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,\n\tdefaultContent: Content | undefined,\n): JoinToken<ASide, AType, BSide, BType, Cardinality, Content> {\n\tstore.joins.set(options.key, new Join(options, defaultContent, store))\n\tconst token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content> = {\n\t\tkey: options.key,\n\t\ttype: `join`,\n\t\ta: options.between[0],\n\t\tb: options.between[1],\n\t\tcardinality: options.cardinality,\n\t}\n\treturn token\n}\n","import type {\n\tCompoundTypedKey,\n\tfindState,\n\tgetState,\n\tJoinOptions,\n\tMutableAtomFamilyToken,\n\tRead,\n\tReadonlyPureSelectorFamilyToken,\n\tRegularAtomFamilyToken,\n\tsetState,\n\tWrite,\n\tWriterToolkit,\n} from \"atom.io\"\nimport { Anarchy } from \"atom.io\"\nimport type { Canonical, Json, stringified } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\nimport type { SetRTXJson } from \"atom.io/transceivers/set-rtx\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport { capitalize } from \"../capitalize\"\nimport {\n\tcreateReadonlyPureSelectorFamily,\n\tcreateRegularAtomFamily,\n\tfindInStore,\n} from \"../families\"\nimport { getFromStore } from \"../get-state\"\nimport type {\n\tBaseExternalStoreConfiguration,\n\tExternalStoreConfiguration,\n} from \"../junction\"\nimport { Junction } from \"../junction\"\nimport type { Molecule } from \"../molecule\"\nimport { createMutableAtomFamily, getJsonFamily, getJsonToken } from \"../mutable\"\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\n\nexport type JoinStateFamilies<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object | null,\n> = Cardinality extends `1:1`\n\t? (Content extends Json.Object\n\t\t\t? {\n\t\t\t\t\treadonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t[AType, Content] | null,\n\t\t\t\t\t\tBType\n\t\t\t\t\t>\n\t\t\t\t} & {\n\t\t\t\t\treadonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t[BType, Content] | null,\n\t\t\t\t\t\tAType\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t: {}) & {\n\t\t\treadonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\tAType | null,\n\t\t\t\tBType\n\t\t\t>\n\t\t} & {\n\t\t\treadonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\tBType | null,\n\t\t\t\tAType\n\t\t\t>\n\t\t}\n\t: Cardinality extends `1:n`\n\t\t? (Content extends Json.Object\n\t\t\t\t? {\n\t\t\t\t\t\treadonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t\t[AType, Content] | null,\n\t\t\t\t\t\t\tBType\n\t\t\t\t\t\t>\n\t\t\t\t\t} & {\n\t\t\t\t\t\treadonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t\t[BType, Content][],\n\t\t\t\t\t\t\tAType\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t: {}) & {\n\t\t\t\treadonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\tAType | null,\n\t\t\t\t\tBType\n\t\t\t\t>\n\t\t\t} & {\n\t\t\t\treadonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\tBType[],\n\t\t\t\t\tAType\n\t\t\t\t>\n\t\t\t}\n\t\t: Cardinality extends `n:n`\n\t\t\t? (Content extends Json.Object\n\t\t\t\t\t? {\n\t\t\t\t\t\t\treadonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t\t\t[AType, Content][],\n\t\t\t\t\t\t\t\tBType\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t} & {\n\t\t\t\t\t\t\treadonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\t\t\t[BType, Content][],\n\t\t\t\t\t\t\t\tAType\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}) & {\n\t\t\t\t\treadonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\tAType[],\n\t\t\t\t\t\tBType\n\t\t\t\t\t>\n\t\t\t\t} & {\n\t\t\t\t\treadonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\tBType[],\n\t\t\t\t\t\tAType\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t: never\n\nexport class Join<\n\tconst ASide extends string,\n\tconst AType extends string,\n\tconst BSide extends string,\n\tconst BType extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object | null = null,\n\tconst ContentKey extends CompoundTypedKey<\n\t\t`content`,\n\t\tASide,\n\t\tBSide\n\t> = CompoundTypedKey<`content`, ASide, BSide>,\n> {\n\tprivate toolkit: WriterToolkit\n\tpublic options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>\n\tpublic defaultContent: Content | undefined\n\tpublic molecules: Map<string, Molecule<any>> = new Map()\n\tpublic relations: Junction<ASide, AType, BSide, BType, Content>\n\tpublic states: JoinStateFamilies<\n\t\tASide,\n\t\tAType,\n\t\tBSide,\n\t\tBType,\n\t\tCardinality,\n\t\tContent\n\t>\n\tpublic core: {\n\t\trelatedKeysAtoms: MutableAtomFamilyToken<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n\tpublic transact(\n\t\ttoolkit: WriterToolkit,\n\t\trun: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void,\n\t): void {\n\t\tconst originalToolkit = this.toolkit\n\t\tthis.toolkit = toolkit\n\t\trun(this)\n\t\tthis.toolkit = originalToolkit\n\t}\n\n\tpublic store: Store\n\tpublic realm: Anarchy\n\n\tpublic [Symbol.dispose](): void {}\n\n\tpublic constructor(\n\t\toptions: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,\n\t\tdefaultContent: Content | undefined,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) {\n\t\ttype AnyKey = AType & BType\n\n\t\tthis.store = store\n\t\tthis.realm = new Anarchy(store)\n\t\tthis.options = options\n\t\tthis.defaultContent = defaultContent\n\n\t\tthis.store.miscResources.set(`join:${options.key}`, this)\n\n\t\tthis.realm.allocate(`root`, options.key)\n\n\t\tthis.toolkit = {\n\t\t\tget: ((...ps: Parameters<typeof getState>) =>\n\t\t\t\tgetFromStore(store, ...ps)) as typeof getState,\n\t\t\tset: ((...ps: Parameters<typeof setState>) => {\n\t\t\t\tsetIntoStore(store, ...ps)\n\t\t\t}) as typeof setState,\n\t\t\tfind: ((...ps: Parameters<typeof findState>) =>\n\t\t\t\tfindInStore(store, ...ps)) as typeof findState,\n\t\t\tjson: (token) => getJsonToken(store, token),\n\t\t}\n\n\t\tconst aSide: ASide = options.between[0]\n\t\tconst bSide: BSide = options.between[1]\n\t\tconst relatedKeysAtoms = createMutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tdefault: () => new SetRTX(),\n\t\t\t\tfromJson: (json) => SetRTX.fromJSON(json),\n\t\t\t\ttoJson: (set) => set.toJSON(),\n\t\t\t},\n\t\t\t[`join`, `relations`],\n\t\t)\n\t\tthis.core = { relatedKeysAtoms }\n\t\tconst getRelatedKeys: Read<\n\t\t\t(key: string) => SetRTX<AType> | SetRTX<BType>\n\t\t> = ({ get }, key) => get(relatedKeysAtoms, key) as any\n\t\tconst addRelation: Write<(a: string, b: string) => void> = (\n\t\t\t{ set },\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tif (!this.store.molecules.has(stringifyJson(a))) {\n\t\t\t\tthis.realm.allocate(options.key, a)\n\t\t\t}\n\t\t\tset(relatedKeysAtoms, a, (aKeys) => aKeys.add(b))\n\t\t\tset(relatedKeysAtoms, b, (bKeys) => bKeys.add(a))\n\t\t}\n\t\tconst deleteRelation: Write<(a: string, b: string) => void> = (\n\t\t\t{ set },\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tset(relatedKeysAtoms, a, (aKeys) => {\n\t\t\t\taKeys.delete(b)\n\t\t\t\treturn aKeys\n\t\t\t})\n\t\t\tset(relatedKeysAtoms, b, (bKeys) => {\n\t\t\t\tbKeys.delete(a)\n\t\t\t\treturn bKeys\n\t\t\t})\n\t\t}\n\t\tconst replaceRelationsSafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (toolkit, a, newRelationsOfA) => {\n\t\t\tconst { find, get, set } = toolkit\n\t\t\tconst relationsOfAState = find(relatedKeysAtoms, a)\n\t\t\tconst currentRelationsOfA = get(relationsOfAState)\n\t\t\tfor (const currentRelationB of currentRelationsOfA) {\n\t\t\t\tconst remainsRelated = newRelationsOfA.includes(currentRelationB)\n\t\t\t\tif (remainsRelated) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tset(relatedKeysAtoms, currentRelationB, (relationsOfB) => {\n\t\t\t\t\trelationsOfB.delete(a)\n\t\t\t\t\treturn relationsOfB\n\t\t\t\t})\n\t\t\t}\n\t\t\tset(relationsOfAState, (relationsOfA) => {\n\t\t\t\trelationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\t\tnextRelationsOfA.clear()\n\t\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\t\tconst relationsOfB = getRelatedKeys(toolkit, newRelationB)\n\t\t\t\t\t\tconst newRelationBIsAlreadyRelated = relationsOfB.has(a as AnyKey)\n\t\t\t\t\t\tif (this.relations.cardinality === `1:n`) {\n\t\t\t\t\t\t\tconst previousOwnersToDispose: string[] = []\n\t\t\t\t\t\t\tfor (const previousOwner of relationsOfB) {\n\t\t\t\t\t\t\t\tif (previousOwner === a) {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst previousOwnerRelations = getRelatedKeys(\n\t\t\t\t\t\t\t\t\ttoolkit,\n\t\t\t\t\t\t\t\t\tpreviousOwner,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tpreviousOwnerRelations.delete(newRelationB as AnyKey)\n\t\t\t\t\t\t\t\tif (previousOwnerRelations.size === 0) {\n\t\t\t\t\t\t\t\t\tpreviousOwnersToDispose.push(previousOwner)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!newRelationBIsAlreadyRelated && relationsOfB.size > 0) {\n\t\t\t\t\t\t\t\trelationsOfB.clear()\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor (const previousOwner of previousOwnersToDispose) {\n\t\t\t\t\t\t\t\tconst sorted = [newRelationB, previousOwner].sort()\n\t\t\t\t\t\t\t\tconst compositeKey = `\"${sorted[0]}:${sorted[1]}\"`\n\t\t\t\t\t\t\t\tthis.molecules.delete(compositeKey)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!newRelationBIsAlreadyRelated) {\n\t\t\t\t\t\t\trelationsOfB.add(a as AnyKey)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnextRelationsOfA.add(newRelationB)\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t})\n\t\t\t\treturn relationsOfA\n\t\t\t})\n\t\t}\n\t\tconst replaceRelationsUnsafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (toolkit, a, newRelationsOfA) => {\n\t\t\tconst { set } = toolkit\n\t\t\tset(relatedKeysAtoms, a, (relationsOfA) => {\n\t\t\t\trelationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\t\tnextRelationsOfA.add(newRelationB)\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t})\n\t\t\t\treturn relationsOfA\n\t\t\t})\n\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\tset(relatedKeysAtoms, newRelationB, (newRelationsB) => {\n\t\t\t\t\tnewRelationsB.add(a)\n\t\t\t\t\treturn newRelationsB\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t\tconst has: Read<(a: string, b?: string) => boolean> = (toolkit, a, b) => {\n\t\t\tconst aKeys = getRelatedKeys(toolkit, a)\n\t\t\treturn b ? aKeys.has(b as AnyKey) : aKeys.size > 0\n\t\t}\n\t\tconst baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\t\tgetRelatedKeys: (key) => getRelatedKeys(this.toolkit, key),\n\t\t\taddRelation: (a, b) => {\n\t\t\t\tthis.store.moleculeJoins.set(\n\t\t\t\t\ta as stringified<Canonical> /* 💥 RECONCILE */,\n\t\t\t\t\toptions.key,\n\t\t\t\t)\n\t\t\t\tthis.store.moleculeJoins.set(\n\t\t\t\t\tb as stringified<Canonical> /* 💥 RECONCILE */,\n\t\t\t\t\toptions.key,\n\t\t\t\t)\n\t\t\t\taddRelation(this.toolkit, a, b)\n\t\t\t},\n\t\t\tdeleteRelation: (a, b) => {\n\t\t\t\tdeleteRelation(this.toolkit, a, b)\n\t\t\t},\n\t\t\treplaceRelationsSafely: (a, bs) => {\n\t\t\t\treplaceRelationsSafely(this.toolkit, a, bs)\n\t\t\t},\n\t\t\treplaceRelationsUnsafely: (a, bs) => {\n\t\t\t\treplaceRelationsUnsafely(this.toolkit, a, bs)\n\t\t\t},\n\t\t\thas: (a, b) => has(this.toolkit, a, b),\n\t\t}\n\t\tlet externalStore: ExternalStoreConfiguration<Content>\n\t\tlet contentAtoms: RegularAtomFamilyToken<Content, string>\n\n\t\tif (defaultContent) {\n\t\t\tcontentAtoms = createRegularAtomFamily<Content, ContentKey>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/content`,\n\t\t\t\t\tdefault: defaultContent,\n\t\t\t\t},\n\t\t\t\t[`join`, `content`],\n\t\t\t)\n\n\t\t\tconst getContent: Read<(key: string) => Content | null> = ({ get }, key) =>\n\t\t\t\tget(contentAtoms, key)\n\t\t\tconst setContent: Write<(key: string, content: Content) => void> = (\n\t\t\t\t{ set },\n\t\t\t\tkey,\n\t\t\t\tcontent,\n\t\t\t) => {\n\t\t\t\tset(contentAtoms, key, content)\n\t\t\t}\n\n\t\t\tconst externalStoreWithContentConfiguration = {\n\t\t\t\tgetContent: (contentKey: ContentKey) => {\n\t\t\t\t\tconst content = getContent(this.toolkit, contentKey)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t\tsetContent: (contentKey: ContentKey, content: Content) => {\n\t\t\t\t\tsetContent(this.toolkit, contentKey, content)\n\t\t\t\t},\n\t\t\t\tdeleteContent: (contentKey: ContentKey) => {\n\t\t\t\t\tthis.realm.deallocate(contentKey)\n\t\t\t\t},\n\t\t\t}\n\t\t\texternalStore = Object.assign(\n\t\t\t\tbaseExternalStoreConfiguration,\n\t\t\t\texternalStoreWithContentConfiguration,\n\t\t\t) as ExternalStoreConfiguration<Content>\n\t\t} else {\n\t\t\texternalStore =\n\t\t\t\tbaseExternalStoreConfiguration as ExternalStoreConfiguration<Content>\n\t\t}\n\t\tconst relations = new Junction<ASide, AType, BSide, BType, Content>(\n\t\t\toptions as any,\n\t\t\t{\n\t\t\t\texternalStore,\n\t\t\t\tisAType: options.isAType,\n\t\t\t\tisBType: options.isBType,\n\t\t\t\tmakeContentKey: (...args) => {\n\t\t\t\t\tconst [a, b] = args\n\t\t\t\t\tconst sorted = args.sort()\n\t\t\t\t\tconst compositeKey = `${sorted[0]}:${sorted[1]}`\n\t\t\t\t\tconst aMolecule = store.molecules.get(stringifyJson(a))\n\t\t\t\t\tconst bMolecule = store.molecules.get(stringifyJson(b))\n\t\t\t\t\tif (!aMolecule) {\n\t\t\t\t\t\tthis.realm.allocate(options.key, a)\n\t\t\t\t\t}\n\t\t\t\t\tif (!bMolecule) {\n\t\t\t\t\t\tthis.realm.allocate(options.key, b)\n\t\t\t\t\t}\n\t\t\t\t\tthis.realm.allocate(a, compositeKey, `all`)\n\t\t\t\t\tthis.realm.claim(b, compositeKey)\n\t\t\t\t\tthis.store.moleculeJoins.set(compositeKey, options.key)\n\t\t\t\t\treturn compositeKey\n\t\t\t\t},\n\t\t\t},\n\t\t)\n\n\t\tconst createSingleKeySelectorFamily = () =>\n\t\t\tcreateReadonlyPureSelectorFamily<string | null, string>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedKey`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(relatedKeysAtoms, key)\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\treturn relatedKey\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t[`join`, `keys`],\n\t\t\t)\n\t\tconst getMultipleKeySelectorFamily = () => {\n\t\t\treturn createReadonlyPureSelectorFamily<string[], string>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedKeys`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(relatedKeysAtoms, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily, key)\n\t\t\t\t\t\t\treturn json.members\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t[`join`, `keys`],\n\t\t\t)\n\t\t}\n\t\tconst createSingleEntrySelectorFamily = () =>\n\t\t\tcreateReadonlyPureSelectorFamily<[string, Content] | null, string>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedEntry`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(x) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(relatedKeysAtoms, x)\n\t\t\t\t\t\t\tfor (const y of relatedKeys) {\n\t\t\t\t\t\t\t\tlet a = relations.isAType?.(x) ? x : undefined\n\t\t\t\t\t\t\t\tlet b = a === undefined ? (x as BType) : undefined\n\t\t\t\t\t\t\t\ta ??= y as AType\n\t\t\t\t\t\t\t\tb ??= y as BType\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(a, b)\n\t\t\t\t\t\t\t\tconst content = get(contentAtoms, contentKey)\n\t\t\t\t\t\t\t\treturn [y, content]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t[`join`, `entries`],\n\t\t\t)\n\t\tconst getMultipleEntrySelectorFamily = () =>\n\t\t\tcreateReadonlyPureSelectorFamily<[string, Content][], string>(\n\t\t\t\tstore,\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedEntries`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(x) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(relatedKeysAtoms, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily, x)\n\t\t\t\t\t\t\treturn json.members.map((y) => {\n\t\t\t\t\t\t\t\tlet a = relations.isAType?.(x) ? x : undefined\n\t\t\t\t\t\t\t\tlet b = a === undefined ? (x as BType) : undefined\n\t\t\t\t\t\t\t\ta ??= y as AType\n\t\t\t\t\t\t\t\tb ??= y as BType\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(a, b)\n\t\t\t\t\t\t\t\tconst content = get(contentAtoms, contentKey)\n\t\t\t\t\t\t\t\treturn [y, content]\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t[`join`, `entries`],\n\t\t\t)\n\n\t\tswitch (options.cardinality) {\n\t\t\tcase `1:1`: {\n\t\t\t\tconst singleRelatedKeySelectors = createSingleKeySelectorFamily()\n\t\t\t\tconst stateKeyA = `${aSide}KeyOf${capitalize(bSide)}` as const\n\t\t\t\tconst stateKeyB = `${bSide}KeyOf${capitalize(aSide)}` as const\n\t\t\t\tconst baseStates = {\n\t\t\t\t\t[stateKeyA]: singleRelatedKeySelectors,\n\t\t\t\t\t[stateKeyB]: singleRelatedKeySelectors,\n\t\t\t\t} as JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\t\tlet states: JoinStateFamilies<\n\t\t\t\t\tASide,\n\t\t\t\t\tAType,\n\t\t\t\t\tBSide,\n\t\t\t\t\tBType,\n\t\t\t\t\tCardinality,\n\t\t\t\t\tContent\n\t\t\t\t>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst singleEntrySelectors = createSingleEntrySelectorFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${bSide}EntryOf${capitalize(aSide)}` as const\n\t\t\t\t\tconst contentStates = {\n\t\t\t\t\t\t[entriesStateKeyA]: singleEntrySelectors,\n\t\t\t\t\t\t[entriesStateKeyB]: singleEntrySelectors,\n\t\t\t\t\t}\n\t\t\t\t\tstates = Object.assign(baseStates, contentStates)\n\t\t\t\t} else {\n\t\t\t\t\tstates = baseStates\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.states = states\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst singleRelatedKeySelectors = createSingleKeySelectorFamily()\n\t\t\t\tconst multipleRelatedKeysSelectors = getMultipleKeySelectorFamily()\n\t\t\t\tconst stateKeyA = `${aSide}KeyOf${capitalize(bSide)}` as const\n\t\t\t\tconst stateKeyB = `${bSide}KeysOf${capitalize(aSide)}` as const\n\t\t\t\tconst baseStates = {\n\t\t\t\t\t[stateKeyA]: singleRelatedKeySelectors,\n\t\t\t\t\t[stateKeyB]: multipleRelatedKeysSelectors,\n\t\t\t\t} as JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\t\tlet states: JoinStateFamilies<\n\t\t\t\t\tASide,\n\t\t\t\t\tAType,\n\t\t\t\t\tBSide,\n\t\t\t\t\tBType,\n\t\t\t\t\tCardinality,\n\t\t\t\t\tContent\n\t\t\t\t>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst singleRelatedEntrySelectors = createSingleEntrySelectorFamily()\n\t\t\t\t\tconst multipleRelatedEntriesSelectors =\n\t\t\t\t\t\tgetMultipleEntrySelectorFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${bSide}EntriesOf${capitalize(\n\t\t\t\t\t\taSide,\n\t\t\t\t\t)}` as const\n\t\t\t\t\tconst contentStates = {\n\t\t\t\t\t\t[entriesStateKeyA]: singleRelatedEntrySelectors,\n\t\t\t\t\t\t[entriesStateKeyB]: multipleRelatedEntriesSelectors,\n\t\t\t\t\t}\n\t\t\t\t\tstates = Object.assign(baseStates, contentStates)\n\t\t\t\t} else {\n\t\t\t\t\tstates = baseStates\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.states = states\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `n:n`: {\n\t\t\t\tconst multipleRelatedKeysSelectors = getMultipleKeySelectorFamily()\n\t\t\t\tconst stateKeyA = `${aSide}KeysOf${capitalize(bSide)}` as const\n\t\t\t\tconst stateKeyB = `${bSide}KeysOf${capitalize(aSide)}` as const\n\t\t\t\tconst baseStates = {\n\t\t\t\t\t[stateKeyA]: multipleRelatedKeysSelectors,\n\t\t\t\t\t[stateKeyB]: multipleRelatedKeysSelectors,\n\t\t\t\t} as JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\t\tlet states: JoinStateFamilies<\n\t\t\t\t\tASide,\n\t\t\t\t\tAType,\n\t\t\t\t\tBSide,\n\t\t\t\t\tBType,\n\t\t\t\t\tCardinality,\n\t\t\t\t\tContent\n\t\t\t\t>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst multipleRelatedEntriesSelectors =\n\t\t\t\t\t\tgetMultipleEntrySelectorFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${aSide}EntriesOf${capitalize(\n\t\t\t\t\t\tbSide,\n\t\t\t\t\t)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${bSide}EntriesOf${capitalize(\n\t\t\t\t\t\taSide,\n\t\t\t\t\t)}` as const\n\t\t\t\t\tconst contentStates = {\n\t\t\t\t\t\t[entriesStateKeyA]: multipleRelatedEntriesSelectors,\n\t\t\t\t\t\t[entriesStateKeyB]: multipleRelatedEntriesSelectors,\n\t\t\t\t\t}\n\t\t\t\t\tstates = Object.assign(baseStates, contentStates)\n\t\t\t\t} else {\n\t\t\t\t\tstates = baseStates\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.states = states\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { JoinToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { IMPLICIT, type Store } from \"../store\"\nimport { Join } from \"./join-internal\"\n\nexport function getJoin<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object | null,\n>(\n\ttoken: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,\n\tstore: Store,\n): Join<ASide, AType, BSide, BType, Cardinality, Content> {\n\tlet myJoin = store.joins.get(token.key)\n\tif (myJoin === undefined) {\n\t\tconst rootJoinMap = IMPLICIT.STORE.joins\n\t\tconst rootJoin = rootJoinMap.get(token.key)\n\t\tif (rootJoin === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`Join \"${token.key}\" not found in store \"${store.config.name}\"`,\n\t\t\t)\n\t\t}\n\t\tmyJoin = new Join(rootJoin.options, rootJoin.defaultContent, store)\n\t\tstore.joins.set(token.key, myJoin)\n\t}\n\treturn myJoin\n}\n","import type { JoinToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Junction } from \"../junction\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { isChildStore } from \"../transaction\"\nimport { getJoin } from \"./get-join\"\n\nexport function editRelationsInStore<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object | null,\n>(\n\ttoken: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,\n\tchange: (relations: Junction<ASide, AType, BSide, BType, Content>) => void,\n\tstore: Store,\n): void {\n\tconst myJoin = getJoin(token, store)\n\tconst target = newest(store)\n\tif (isChildStore(target)) {\n\t\tconst { toolkit } = target.transactionMeta\n\t\tmyJoin.transact(toolkit, ({ relations }) => {\n\t\t\tchange(relations)\n\t\t})\n\t} else {\n\t\tchange(myJoin.relations)\n\t}\n}\n","import type { JoinStates, JoinToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { capitalize } from \"../capitalize\"\nimport { findInStore } from \"../families\"\nimport type { Store } from \"../store\"\nimport { getJoin } from \"./get-join\"\n\nexport function findRelationsInStore<\n\tASide extends string,\n\tAType extends string,\n\tBSide extends string,\n\tBType extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object | null,\n>(\n\ttoken: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,\n\tkey: AType | BType,\n\tstore: Store,\n): JoinStates<ASide, AType, BSide, BType, Cardinality, Content> {\n\tconst myJoin = getJoin(token, store)\n\tlet relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>\n\tswitch (token.cardinality satisfies `1:1` | `1:n` | `n:n`) {\n\t\tcase `1:1`: {\n\t\t\tconst keyAB = `${token.a}KeyOf${capitalize(token.b)}`\n\t\t\tconst keyBA = `${token.b}KeyOf${capitalize(token.a)}`\n\t\t\trelations = {\n\t\t\t\tget [keyAB]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyAB = myJoin.states[keyAB as any]\n\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t\tget [keyBA]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyBA = myJoin.states[keyBA as any]\n\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\tconst entryAB = `${token.a}EntryOf${capitalize(token.b)}`\n\t\t\tif (entryAB in myJoin.states) {\n\t\t\t\tconst entryBA = `${token.b}EntryOf${capitalize(token.a)}`\n\t\t\t\tObject.assign(relations, {\n\t\t\t\t\tget [entryAB]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyAB = myJoin.states[entryAB as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t\tget [entryBA]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyBA = myJoin.states[entryBA as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase `1:n`: {\n\t\t\tconst keyAB = `${token.a}KeyOf${capitalize(token.b)}`\n\t\t\tconst keysBA = `${token.b}KeysOf${capitalize(token.a)}`\n\t\t\trelations = {\n\t\t\t\tget [keyAB]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyAB = myJoin.states[keyAB as any]\n\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t\tget [keysBA]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyBA = myJoin.states[keysBA as any]\n\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\tconst entryAB = `${token.a}EntryOf${capitalize(token.b)}`\n\t\t\tif (entryAB in myJoin.states) {\n\t\t\t\tconst entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`\n\t\t\t\tObject.assign(relations, {\n\t\t\t\t\tget [entryAB]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyAB = myJoin.states[entryAB as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t\tget [entriesBA]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyBA = myJoin.states[entriesBA as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase `n:n`: {\n\t\t\tconst keysAB = `${token.a}KeysOf${capitalize(token.b)}`\n\t\t\tconst keysBA = `${token.b}KeysOf${capitalize(token.a)}`\n\t\t\trelations = {\n\t\t\t\tget [keysAB]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyAB = myJoin.states[keysAB as any]\n\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t\tget [keysBA]() {\n\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\tconst familyBA = myJoin.states[keysBA as any]\n\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\treturn state\n\t\t\t\t},\n\t\t\t} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>\n\t\t\tconst entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`\n\t\t\tif (entriesAB in myJoin.states) {\n\t\t\t\tconst entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`\n\t\t\t\tObject.assign(relations, {\n\t\t\t\t\tget [entriesAB]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyAB = myJoin.states[entriesAB as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyAB, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t\tget [entriesBA]() {\n\t\t\t\t\t\t// @ts-expect-error way too complicated to represent\n\t\t\t\t\t\tconst familyBA = myJoin.states[entriesBA as any]\n\t\t\t\t\t\tconst state = findInStore(store, familyBA, key)\n\t\t\t\t\t\treturn state\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\treturn relations\n}\n","import type { JoinToken, MutableAtomFamilyToken } from \"atom.io\"\nimport type { SetRTX, SetRTXJson } from \"atom.io/transceivers/set-rtx\"\n\nimport type { Store } from \"../store\"\nimport { getJoin } from \"./get-join\"\n\nexport function getInternalRelationsFromStore(\n\ttoken: JoinToken<any, any, any, any, any, any>,\n\tstore: Store,\n): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {\n\tconst myJoin = getJoin(token, store)\n\tconst family = myJoin.core.relatedKeysAtoms\n\treturn family\n}\n","export type ReservedIntrospectionKey = `🔍 ${string}`\n\nexport function isReservedIntrospectionKey(\n\tvalue: string,\n): value is ReservedIntrospectionKey {\n\treturn value.startsWith(`🔍 `)\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tFamilyMetadata,\n\tMoleculeCreation,\n\tMoleculeDisposal,\n\tReadableToken,\n\tStateCreation,\n\tStateDisposal,\n\tStateUpdate,\n\tTimelineManageable,\n\tTimelineOptions,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTokenType,\n\tTransactionToken,\n\tTransactionUpdate,\n\tTransactionUpdateContent,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { getUpdateToken } from \"../mutable\"\nimport { type Store, withdraw } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { isChildStore } from \"../transaction\"\nimport type { Flat, Func } from \"../utility-types\"\n\nexport type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> = Flat<\n\tStateUpdate<TokenType<ManagedAtom>> & {\n\t\tkey: string\n\t\ttype: `atom_update`\n\t\ttimestamp: number\n\t\tfamily?: FamilyMetadata\n\t}\n>\nexport type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\ttype: `selector_update`\n\ttimestamp: number\n\tatomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[]\n}\nexport type TimelineTransactionUpdate = Flat<\n\tTransactionUpdate<Func> & {\n\t\tkey: string\n\t\ttype: `transaction_update`\n\t\ttimestamp: number\n\t}\n>\nexport type TimelineStateCreation<T extends ReadableToken<any>> = Flat<\n\tStateCreation<T> & { timestamp: number }\n>\nexport type TimelineStateDisposal<T extends ReadableToken<any>> = Flat<\n\tStateDisposal<T> & { timestamp: number }\n>\nexport type TimelineMoleculeCreation = Flat<\n\tMoleculeCreation & { timestamp: number }\n>\nexport type TimelineMoleculeDisposal = Flat<\n\tMoleculeDisposal & { timestamp: number }\n>\n\nexport type Timeline<ManagedAtom extends TimelineManageable> = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<ManagedAtom>,\n\t) => boolean\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineUpdate<ManagedAtom>[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: Store) => void\n\tsubject: Subject<TimelineUpdate<ManagedAtom> | `redo` | `undo`>\n\tsubscriptions: Map<string, () => void>\n}\n\nexport function createTimeline<ManagedAtom extends TimelineManageable>(\n\tstore: Store,\n\toptions: TimelineOptions<ManagedAtom>,\n\tdata?: Timeline<ManagedAtom>,\n): TimelineToken<ManagedAtom> {\n\tconst tl: Timeline<ManagedAtom> = {\n\t\ttype: `timeline`,\n\t\tkey: options.key,\n\t\tat: 0,\n\n\t\ttimeTraveling: null,\n\t\tselectorTime: null,\n\t\ttransactionKey: null,\n\t\t...data,\n\t\thistory: data?.history.map((update) => ({ ...update })) ?? [],\n\t\tinstall: (s) => createTimeline(s, options, tl),\n\t\tsubject: new Subject(),\n\t\tsubscriptions: new Map(),\n\t}\n\tif (options.shouldCapture) {\n\t\ttl.shouldCapture = options.shouldCapture\n\t}\n\tconst timelineKey = options.key\n\tconst target = newest(store)\n\tfor (const initialTopic of options.scope) {\n\t\tswitch (initialTopic.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\t{\n\t\t\t\t\tconst atomToken: AtomToken<ManagedAtom> = initialTopic\n\t\t\t\t\tconst atomKey = atomToken.key\n\t\t\t\t\tlet existingTimelineKey = target.timelineTopics.getRelatedKey(atomKey)\n\t\t\t\t\tif (`family` in atomToken) {\n\t\t\t\t\t\tconst familyKey = atomToken.family.key\n\t\t\t\t\t\texistingTimelineKey = target.timelineTopics.getRelatedKey(familyKey)\n\t\t\t\t\t\tif (existingTimelineKey) {\n\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t\t\t`Failed to add atom \"${atomKey}\" because its family \"${familyKey}\" already belongs to timeline \"${existingTimelineKey}\"`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (existingTimelineKey) {\n\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t\t`Failed to add atom \"${atomKey}\" because it already belongs to timeline \"${existingTimelineKey}\"`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\taddAtomToTimeline(store, atomToken, tl)\n\t\t\t\t}\n\t\t\t\tbreak\n\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\t\t{\n\t\t\t\t\tconst familyToken: AtomFamilyToken<any, any> = initialTopic\n\t\t\t\t\tconst familyKey = familyToken.key\n\t\t\t\t\tconst existingTimelineKey =\n\t\t\t\t\t\ttarget.timelineTopics.getRelatedKey(familyKey)\n\t\t\t\t\tif (existingTimelineKey) {\n\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t\t`Failed to add atom family \"${familyKey}\" because it already belongs to timeline \"${existingTimelineKey}\"`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\taddAtomFamilyToTimeline(store, familyToken, tl)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\tstore.timelines.set(options.key, tl)\n\tconst token: TimelineToken<ManagedAtom> = {\n\t\tkey: timelineKey,\n\t\ttype: `timeline`,\n\t}\n\tstore.on.timelineCreation.next(token)\n\treturn token\n}\n\nfunction addAtomToTimeline(\n\tstore: Store,\n\tatomToken: AtomToken<any>,\n\ttl: Timeline<any>,\n): void {\n\tlet maybeAtom = withdraw(store, atomToken)\n\tif (maybeAtom.type === `mutable_atom`) {\n\t\tconst updateToken = getUpdateToken(maybeAtom)\n\t\tmaybeAtom = withdraw(store, updateToken)\n\t}\n\tconst atom = maybeAtom\n\tstore.timelineTopics.set(\n\t\t{ topicKey: atom.key, timelineKey: tl.key },\n\t\t{ topicType: `atom` },\n\t)\n\n\ttl.subscriptions.set(\n\t\tatom.key,\n\t\tatom.subject.subscribe(\n\t\t\t`timeline`,\n\t\t\tfunction timelineCapturesAtomUpdate(update) {\n\t\t\t\tconst target = newest(store)\n\t\t\t\tconst currentSelectorKey =\n\t\t\t\t\tstore.operation.open &&\n\t\t\t\t\tstore.operation.token.type === `writable_pure_selector`\n\t\t\t\t\t\t? store.operation.token.key\n\t\t\t\t\t\t: null\n\t\t\t\tconst currentSelectorTime =\n\t\t\t\t\tstore.operation.open &&\n\t\t\t\t\tstore.operation.token.type === `writable_pure_selector`\n\t\t\t\t\t\t? store.operation.time\n\t\t\t\t\t\t: null\n\n\t\t\t\tconst txUpdateInProgress = target.on.transactionApplying.state?.update\n\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`⏳`,\n\t\t\t\t\t`timeline`,\n\t\t\t\t\ttl.key,\n\t\t\t\t\t`atom`,\n\t\t\t\t\tatomToken.key,\n\t\t\t\t\t`went`,\n\t\t\t\t\tupdate.oldValue,\n\t\t\t\t\t`->`,\n\t\t\t\t\tupdate.newValue,\n\t\t\t\t\ttxUpdateInProgress\n\t\t\t\t\t\t? `in transaction \"${txUpdateInProgress.key}\"`\n\t\t\t\t\t\t: currentSelectorKey\n\t\t\t\t\t\t\t? `in selector \"${currentSelectorKey}\"`\n\t\t\t\t\t\t\t: ``,\n\t\t\t\t)\n\t\t\t\tif (tl.timeTraveling === null) {\n\t\t\t\t\tif (txUpdateInProgress) {\n\t\t\t\t\t\tjoinTransaction(store, tl, txUpdateInProgress)\n\t\t\t\t\t} else if (currentSelectorKey && currentSelectorTime) {\n\t\t\t\t\t\tlet latestUpdate: TimelineUpdate<any> | undefined = tl.history.at(-1)\n\n\t\t\t\t\t\tif (currentSelectorTime !== tl.selectorTime) {\n\t\t\t\t\t\t\tlatestUpdate = {\n\t\t\t\t\t\t\t\ttype: `selector_update`,\n\t\t\t\t\t\t\t\ttimestamp: currentSelectorTime,\n\t\t\t\t\t\t\t\tkey: currentSelectorKey,\n\t\t\t\t\t\t\t\tatomUpdates: [],\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlatestUpdate.atomUpdates.push({\n\t\t\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\t\t...update,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttl.history.push(latestUpdate)\n\n\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t`⌛`,\n\t\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t\t`got a selector_update \"${currentSelectorKey}\" with`,\n\t\t\t\t\t\t\t\tlatestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),\n\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\t\ttl.selectorTime = currentSelectorTime\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (latestUpdate?.type === `selector_update`) {\n\t\t\t\t\t\t\t\tlatestUpdate.atomUpdates.push({\n\t\t\t\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\t\t\t...update,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t\t`⌛`,\n\t\t\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t\t\t`set selector_update \"${currentSelectorKey}\" to`,\n\t\t\t\t\t\t\t\t\tlatestUpdate?.atomUpdates.map((atomUpdate) => atomUpdate.key),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (latestUpdate) {\n\t\t\t\t\t\t\tconst willCaptureSelectorUpdate =\n\t\t\t\t\t\t\t\ttl.shouldCapture?.(latestUpdate, tl) ?? true\n\t\t\t\t\t\t\tif (willCaptureSelectorUpdate) {\n\t\t\t\t\t\t\t\ttl.subject.next(latestUpdate)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\ttl.history.pop()\n\t\t\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst timestamp = Date.now()\n\t\t\t\t\t\ttl.selectorTime = null\n\t\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst atomUpdate: TimelineAtomUpdate<any> = {\n\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\t\toldValue: update.oldValue,\n\t\t\t\t\t\t\tnewValue: update.newValue,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (atom.family) {\n\t\t\t\t\t\t\tatomUpdate.family = atom.family\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true\n\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t`⌛`,\n\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t`got an atom_update to \"${atom.key}\"`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (willCapture) {\n\t\t\t\t\t\t\ttl.history.push(atomUpdate)\n\t\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\t\ttl.subject.next(atomUpdate)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t),\n\t)\n}\n\nfunction addAtomFamilyToTimeline(\n\tstore: Store,\n\tatomFamilyToken: AtomFamilyToken<any, any>,\n\ttl: Timeline<any>,\n): void {\n\tconst family = withdraw(store, atomFamilyToken)\n\tstore.timelineTopics.set(\n\t\t{ topicKey: family.key, timelineKey: tl.key },\n\t\t{ topicType: `atom_family` },\n\t)\n\ttl.subscriptions.set(\n\t\tfamily.key,\n\t\tfamily.subject.subscribe(\n\t\t\t`timeline`,\n\t\t\tfunction timelineCapturesStateLifecycleEvent(creationOrDisposal) {\n\t\t\t\thandleStateLifecycleEvent(store, creationOrDisposal, tl)\n\t\t\t},\n\t\t),\n\t)\n\tfor (const atom of store.atoms.values()) {\n\t\tif (atom.family?.key === family.key) {\n\t\t\taddAtomToTimeline(store, atom, tl)\n\t\t}\n\t}\n}\n\nfunction joinTransaction(\n\tstore: Store,\n\ttl: Timeline<any>,\n\ttxUpdateInProgress: TransactionUpdate<Func>,\n) {\n\tconst currentTxKey = txUpdateInProgress.key\n\tconst currentTxInstanceId = txUpdateInProgress.id\n\tconst currentTxToken: TransactionToken<any> = {\n\t\tkey: currentTxKey,\n\t\ttype: `transaction`,\n\t}\n\tconst currentTransaction = withdraw(store, currentTxToken)\n\tif (currentTxKey && tl.transactionKey === null) {\n\t\ttl.transactionKey = currentTxKey\n\t\tconst unsubscribe = currentTransaction.subject.subscribe(\n\t\t\t`timeline:${tl.key}`,\n\t\t\t(transactionUpdate) => {\n\t\t\t\tunsubscribe()\n\t\t\t\ttl.transactionKey = null\n\t\t\t\tif (tl.timeTraveling === null && currentTxInstanceId) {\n\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t}\n\n\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we are in the context of this timeline\n\t\t\t\t\tconst timelineTopics = store.timelineTopics.getRelatedKeys(tl.key)!\n\n\t\t\t\t\tconst updates = filterTransactionUpdates(\n\t\t\t\t\t\ttransactionUpdate.updates,\n\t\t\t\t\t\ttimelineTopics,\n\t\t\t\t\t)\n\n\t\t\t\t\tconst timelineTransactionUpdate: TimelineTransactionUpdate = {\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t...transactionUpdate,\n\t\t\t\t\t\tupdates,\n\t\t\t\t\t}\n\t\t\t\t\tconst willCapture =\n\t\t\t\t\t\ttl.shouldCapture?.(timelineTransactionUpdate, tl) ?? true\n\t\t\t\t\tif (willCapture) {\n\t\t\t\t\t\ttl.history.push(timelineTransactionUpdate)\n\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\ttl.subject.next(timelineTransactionUpdate)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n}\n\nfunction filterTransactionUpdates(\n\tupdates: TransactionUpdateContent[],\n\ttimelineTopics: Set<string>,\n): TransactionUpdateContent[] {\n\treturn updates\n\t\t.filter((updateFromTx) => {\n\t\t\tif (updateFromTx.type === `transaction_update`) {\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\tlet key: string\n\t\t\tlet familyKey: string | undefined\n\t\t\tswitch (updateFromTx.type) {\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\tkey = updateFromTx.token.key\n\t\t\t\t\tfamilyKey = updateFromTx.token.family?.key\n\t\t\t\t\tbreak\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\t\treturn true // always include\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `selector_update`:\n\t\t\t\t\tkey = updateFromTx.key\n\t\t\t\t\tfamilyKey = updateFromTx.family?.key\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t\ttimelineTopics.has(key)\n\t\t\tif (familyKey && timelineTopics.has(familyKey)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn timelineTopics.has(key)\n\t\t})\n\t\t.map((updateFromTx) => {\n\t\t\tif (`updates` in updateFromTx) {\n\t\t\t\treturn {\n\t\t\t\t\t...updateFromTx,\n\t\t\t\t\tupdates: filterTransactionUpdates(\n\t\t\t\t\t\tupdateFromTx.updates,\n\t\t\t\t\t\ttimelineTopics,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn updateFromTx\n\t\t})\n}\n\nfunction handleStateLifecycleEvent(\n\tstore: Store,\n\tevent: StateCreation<any> | StateDisposal<any>,\n\ttl: Timeline<any>,\n): void {\n\tconst timestamp = Date.now()\n\tconst timelineEvent = Object.assign(event, {\n\t\ttimestamp,\n\t}) as TimelineUpdate<any>\n\tif (!tl.timeTraveling) {\n\t\tconst target = newest(store)\n\t\tif (isChildStore(target)) {\n\t\t\t// we don't want to update the true timeline while we are in a transaction\n\t\t} else {\n\t\t\tconst txUpdateInProgress = target.on.transactionApplying.state\n\t\t\tif (txUpdateInProgress) {\n\t\t\t\tjoinTransaction(store, tl, txUpdateInProgress.update)\n\t\t\t} else {\n\t\t\t\ttl.history.push(timelineEvent)\n\t\t\t\ttl.at = tl.history.length\n\t\t\t\ttl.subject.next(timelineEvent)\n\t\t\t}\n\t\t}\n\t}\n\tswitch (event.type) {\n\t\tcase `state_creation`:\n\t\t\taddAtomToTimeline(store, event.token, tl)\n\t\t\tbreak\n\t\tcase `state_disposal`:\n\t\t\ttl.subscriptions.get(event.token.key)?.()\n\t\t\ttl.subscriptions.delete(event.token.key)\n\t\t\tbreak\n\t}\n}\n","import type { TimelineToken } from \"atom.io\"\n\nimport {\n\tingestAtomUpdate,\n\tingestCreationEvent,\n\tingestDisposalEvent,\n\tingestSelectorUpdate,\n\tingestTransactionUpdate,\n} from \"../ingest-updates\"\nimport type { Store } from \"../store\"\n\nexport const timeTravel = (\n\tstore: Store,\n\taction: `redo` | `undo`,\n\ttoken: TimelineToken<any>,\n): void => {\n\tstore.logger.info(\n\t\taction === `redo` ? `⏩` : `⏪`,\n\t\t`timeline`,\n\t\ttoken.key,\n\t\taction,\n\t)\n\tconst timelineData = store.timelines.get(token.key)\n\tif (!timelineData) {\n\t\tstore.logger.error(\n\t\t\t`🐞`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Failed to ${action}. This timeline has not been initialized.`,\n\t\t)\n\t\treturn\n\t}\n\tif (\n\t\t(action === `redo` && timelineData.at === timelineData.history.length) ||\n\t\t(action === `undo` && timelineData.at === 0)\n\t) {\n\t\tstore.logger.warn(\n\t\t\t`💁`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Failed to ${action} at the ${\n\t\t\t\taction === `redo` ? `end` : `beginning`\n\t\t\t} of timeline \"${token.key}\". There is nothing to ${action}.`,\n\t\t)\n\t\treturn\n\t}\n\n\ttimelineData.timeTraveling = action === `redo` ? `into_future` : `into_past`\n\tif (action === `undo`) {\n\t\t--timelineData.at\n\t}\n\n\tconst update = timelineData.history[timelineData.at]\n\tconst applying = action === `redo` ? `newValue` : `oldValue`\n\n\tswitch (update.type) {\n\t\tcase `atom_update`: {\n\t\t\tingestAtomUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `selector_update`: {\n\t\t\tingestSelectorUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `transaction_update`: {\n\t\t\tingestTransactionUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `state_creation`: {\n\t\t\tingestCreationEvent(update, applying, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `state_disposal`: {\n\t\t\tingestDisposalEvent(update, applying, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `molecule_creation`:\n\t\tcase `molecule_disposal`:\n\t}\n\n\tif (action === `redo`) {\n\t\t++timelineData.at\n\t}\n\n\ttimelineData.subject.next(action)\n\ttimelineData.timeTraveling = null\n\tstore.logger.info(\n\t\t`⏹️`,\n\t\t`timeline`,\n\t\ttoken.key,\n\t\t`\"${token.key}\" is now at ${timelineData.at} / ${timelineData.history.length}`,\n\t)\n}\n"],"mappings":";;;;;;AAAA,SAAgB,UAAUA,SAAuB,KAAK,QAAgB;AACrE,QAAO,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;AACrC;;;;ACID,SAAgB,OAA0BC,OAAa;AACtD,QAAO,MAAM,UAAU,MACtB,QAAQ,MAAM;AAEf,QAAO;AACP;;;;ACXD,IAAa,iBAAb,MAAa,eAAkB;CAC9B,AAAU;CACV,AAAU,SAAS;CAGn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