atom.io 0.38.0 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["length: number","COUNTERFEIT: unique symbol","stateToken: ReadableToken<any> & {\n\t\tcounterfeit?: boolean\n\t}","a: AType | undefined","b: BType | undefined","a: AType","b: BType","content: Content | undefined","singleRelation: AType | BType | undefined","superResolve: ((value: T) => void) | undefined","superReject: ((reason?: any) => void) | undefined","mutableAtom","def: T","update: StateUpdate<T>","token: WritableToken<T>","atomUpdate: AtomUpdateEvent<AtomToken<T>>","protoUpdate: [T, T]","RESET_STATE: unique symbol","token: WritableToken<T>","family: WritableFamilyToken<T, Canonical> | null","key: Canonical | null","oldValue: T","newValue: T","constant: T","protoUpdate: [T, T]","invalidKeys: stringified<Canonical>[]","creationEvent: MoleculeCreationEvent","compoundKey: CompoundTypedKey<T, A, B>","join","provenance: stringified<Canonical>[]","values: [string, any][]","disposalEvent: MoleculeDisposalEvent","transferEvent: MoleculeTransferEvent","exclusivity: `exclusive` | undefined","updates: AtomUpdateEvent<AtomOnly<TimelineManageable>>[]","childBase: Omit<ChildStore, `transactionMeta`>","transactionMeta: TransactionProgress<Fn>","child: ChildStore","newTransaction: Transaction<F>","token","target","MUST_CREATE: unique symbol","stateToken: ReadableToken<T, K>","willCreate: boolean","OWN_OP: unique symbol","JOIN_OP: unique symbol","existingToken: WritableToken<T> | undefined","brandNewToken: WritableToken<T> | undefined","token: WritableToken<T>","family: WritableFamilyToken<T, Canonical> | null","key: Canonical | null","value: New | typeof RESET_STATE | ((oldValue: T) => New)","target: Store & { operation: OpenOperation }","protoUpdate: [T, T]","dependencyValue: unknown","readonlySelector: ReadonlyHeldSelector<T>","token: ReadonlyHeldSelectorToken<T>","readonlySelector: ReadonlyPureSelector<T>","token: ReadonlyPureSelectorToken<T>","mySelector: WritableHeldSelector<T>","token: WritableHeldSelectorToken<T>","mySelector: WritablePureSelector<T>","token: WritablePureSelectorToken<T>","state","familyToken: SelectorFamilyToken<any, any>","family: FamilyMetadata","family: FamilyMetadata","individualOptions: RegularAtomOptions<T>","atomFamily","family: FamilyMetadata","family: FamilyMetadata","selectorFamily","family: FamilyMetadata","selectorFamily","state: Molecule<any> | ReadableState<any> | undefined","token: ReadableToken<any>","existingToken: ReadableToken<T> | undefined","brandNewToken: ReadableToken<T> | undefined","familyToken: ReadableFamilyToken<T, K> | undefined","subKey: K | undefined","token: ReadableToken<T, K>","unsubscribe","updateHandler: UpdateHandler<T>","withdrawn: AtomIOInternalResource | undefined","target: Store | null","familyMetaData: FamilyMetadata | undefined","newAtom: MutableAtom<T>","cleanupFunctions: (() => void)[]","familyToken: MutableAtomFamilyToken<T & Transceiver<any, any, any>, K>","family: FamilyMetadata","individualOptions: MutableAtomOptions<T>","atomFamily","jsonFamilyToken: WritablePureSelectorFamilyToken<AsJSON<T>, string>","token: WritablePureSelectorToken<AsJSON<T>>","updateFamily: AtomFamily<SignalFrom<T>, K>","updateToken: RegularAtomToken<SignalFrom<T>>","IMPLICIT: { readonly STORE: Store }","newAtom: RegularAtom<T>","cleanupFunctions: (() => void)[]","atomFamily","disposal: AtomDisposalEvent<AtomToken<any>>","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) => ViewOf<Content> | null>","setContent: Write<(key: string, content: Content) => void>","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>","relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>","tl: Timeline<ManagedAtom>","atomToken: AtomToken<ManagedAtom>","familyToken: AtomFamilyToken<any, any>","token: TimelineToken<ManagedAtom>","latestUpdate: TimelineEvent<any> | undefined","atomUpdate: AtomUpdateEvent<any>","currentTxToken: TransactionToken<any>","timelineTransactionUpdate: TransactionOutcomeEvent<\n\t\t\t\t\t\tTransactionToken<any>\n\t\t\t\t\t>","key: string","familyKey: string | undefined"],"sources":["../../src/internal/arbitrary.ts","../../src/internal/lineage.ts","../../src/internal/store/circular-buffer.ts","../../src/internal/store/deposit.ts","../../src/internal/store/mint-or-counterfeit.ts","../../src/internal/junction.ts","../../src/internal/subject.ts","../../src/internal/subscribe/recall-state.ts","../../src/internal/get-state/get-fallback.ts","../../src/internal/future.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/families/get-family-of-token.ts","../../src/internal/transaction/abort-transaction.ts","../../src/internal/not-found-error.ts","../../src/internal/transaction/act-upon-store.ts","../../src/internal/set-state/become.ts","../../src/internal/set-state/dispatch-state-update.ts","../../src/internal/set-state/set-atom.ts","../../src/internal/set-state/reset-atom-or-selector.ts","../../src/internal/set-state/set-into-store.ts","../../src/internal/set-state/reset-in-store.ts","../../src/internal/set-state/set-selector.ts","../../src/internal/set-state/set-atom-or-selector.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/families/init-family-member.ts","../../src/internal/families/mint-in-store.ts","../../src/internal/set-state/operate-on-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/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/seek-in-store.ts","../../src/internal/families/find-in-store.ts","../../src/internal/families/dispose-from-store.ts","../../src/internal/get-state/reduce-reference.ts","../../src/internal/get-state/get-from-store.ts","../../src/internal/subscribe/subscribe-to-root-atoms.ts","../../src/internal/subscribe/subscribe-to-state.ts","../../src/internal/store/withdraw.ts","../../src/internal/subscribe/subscribe-to-timeline.ts","../../src/internal/subscribe/subscribe-to-transaction.ts","../../src/internal/subscribe/subscribe-in-store.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/atom/create-regular-atom.ts","../../src/internal/atom/dispose-atom.ts","../../src/internal/atom/has-role.ts","../../src/internal/capitalize.ts","../../src/internal/install-into-store.ts","../../src/internal/join/join-internal.ts","../../src/internal/join/create-join.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\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 } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tFn,\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, any, any>>(\n\tstate: MutableAtom<T>,\n): MutableAtomToken<T>\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, any, any>,\n\tK extends Canonical,\n>(state: MutableAtomFamily<T, K>): MutableAtomFamilyToken<T, 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 Fn>(state: Transaction<T>): 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 {\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 } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\n\nexport const COUNTERFEIT: unique symbol = Symbol(`counterfeit`)\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 mint<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n\tKey extends K,\n>(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): RegularAtomToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): AtomToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): WritablePureSelectorToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): ReadonlyPureSelectorToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): SelectorToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): WritableToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): ReadableToken<T>\n\nexport function mint(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n\tcounterfeit?: typeof COUNTERFEIT,\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: ReadableToken<any> & {\n\t\tcounterfeit?: boolean\n\t} = {\n\t\tkey: fullKey,\n\t\ttype,\n\t\tfamily: {\n\t\t\tkey: token.key,\n\t\t\tsubKey,\n\t\t},\n\t}\n\n\tif (counterfeit) {\n\t\tstateToken.counterfeit = true\n\t}\n\n\treturn stateToken\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 { ReadableToken } from \"atom.io\"\nimport { type Canonical, stringifyJson } from \"atom.io/json\"\n\nimport type { ReadableFamily } from \"..\"\nimport type { Store } from \"../store\"\n\nexport function getFallback<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K>,\n\tfamily: ReadableFamily<T, K>,\n\tsubKey: K,\n): T {\n\tconst disposal = store.disposalTraces.buffer.find(\n\t\t(item) => item?.key === stringifyJson(subKey),\n\t)\n\tstore.logger.error(\n\t\t`❌`,\n\t\ttoken.type,\n\t\ttoken.key,\n\t\t`gets a fallback value because key`,\n\t\tsubKey,\n\t\t`is not allocated`,\n\t\tdisposal\n\t\t\t? `This key was previously disposed:\\n${disposal.trace}`\n\t\t\t: `(no previous disposal trace found)`,\n\t)\n\tswitch (family.type) {\n\t\tcase `mutable_atom_family`: {\n\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\t}\n\t\t\tconst defaultValue = new family.class()\n\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\treturn defaultValue\n\t\t}\n\t\tcase `atom_family`: {\n\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\t}\n\t\t\tconst def = family.default as (key: K) => T\n\t\t\tconst defaultValue = def(subKey)\n\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\treturn defaultValue\n\t\t}\n\t\tcase `readonly_pure_selector_family`:\n\t\tcase `writable_pure_selector_family`:\n\t\tcase `readonly_held_selector_family`:\n\t\tcase `writable_held_selector_family`: {\n\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\t}\n\t\t\tconst defaultValue = family.default(subKey)\n\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\treturn defaultValue\n\t\t}\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 { LazyMap } from \"../lazy-map\"\nimport type { Store } from \"../store\"\nimport type { Fn } 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<Fn>\n\tparent: ChildStore | RootStore\n\tchild: ChildStore | null\n\tvalueMap: LazyMap<string, any>\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| OpenOperation<any>\n\t| {\n\t\t\topen: false\n\t }\nexport type OpenOperation<R extends ReadableToken<any> = ReadableToken<any>> = {\n\topen: true\n\ttoken: R\n\tdone: Set<string>\n\tprev: Map<string, any>\n\ttimestamp: number\n}\n\nexport function openOperation(\n\tstore: Store,\n\ttoken: ReadableToken<any>,\n): number | (Store & { operation: OpenOperation }) {\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\ttimestamp: 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\tisChildStore(store)\n\t\t\t\t? ` ${store.transactionMeta.phase} \"${store.transactionMeta.update.token.key}\"`\n\t\t\t\t: ``\n\t\t}`,\n\t)\n\treturn store as Store & { operation: OpenOperation }\n}\n\nexport function 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 } from \"..\"\nimport { evictCachedValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Store } from \"../store\"\n\nexport function evictDownstreamFromAtom(store: Store, atom: Atom<any>): void {\n\tconst target = newest(store)\n\tconst { key, type } = atom\n\tconst downstreamKeys = target.selectorAtoms.getRelatedKeys(key)\n\ttarget.logger.info(\n\t\t`🧹`,\n\t\ttype,\n\t\tkey,\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\ttype,\n\t\t\t\tkey,\n\t\t\t\t`[ ${[...target.operation.done].join(`, `)} ] already done`,\n\t\t\t)\n\t\t}\n\t\tfor (const downstreamKey of downstreamKeys) {\n\t\t\tif (isDone(target, downstreamKey)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tevictCachedValue(target, downstreamKey)\n\t\t\tmarkDone(target, downstreamKey)\n\t\t}\n\t}\n}\n\nexport function evictDownstreamFromSelector(\n\tstore: Store,\n\tselectorKey: string,\n): void {\n\tconst target = newest(store)\n\tconst relationEntries = target.selectorGraph\n\t\t.getRelationEntries({\n\t\t\tupstreamSelectorKey: selectorKey,\n\t\t})\n\t\t.filter(([_, { source }]) => source === selectorKey)\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\tevictDownstreamFromSelector(store, downstreamSelectorKey)\n\t}\n}\n","import type { ReadableState, Transceiver } from \".\"\nimport { closeOperation, isChildStore, openOperation, Tracker } from \".\"\nimport { Future } from \"./future\"\nimport {\n\tevictDownstreamFromAtom,\n\tevictDownstreamFromSelector,\n} from \"./set-state/evict-downstream\"\nimport type { Store } from \"./store\"\n\nexport function writeToCache<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tvalue: T,\n\t// subject: Subject<StateUpdate<unknown>>,\n): T\nexport function writeToCache<T extends Promise<any>>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tvalue: T,\n\t// subject: Subject<StateUpdate<unknown>>,\n): Future<Awaited<T>>\nexport function writeToCache<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tvalue: T,\n\t// subject: Subject<StateUpdate<unknown>>,\n): Future<T> | T {\n\tconst { key, subject, type } = state\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\topenOperation(target, state)\n\t\t\t\t\twriteToCache(target, state, resolved)\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase `atom`:\n\t\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\t\tevictDownstreamFromAtom(target, state)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase `readonly_pure_selector`:\n\t\t\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\t\t\t\tevictDownstreamFromSelector(target, key)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t// held selectors, by definitions, don't become promises\n\t\t\t\t\t}\n\t\t\t\t\tcloseOperation(target)\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\n/**\n * @param target - the newest layer of the store\n * @param state - the state to read from cache\n * @param mut - whether the value is intended to be mutable\n * @returns the state's current value\n */\nexport function readFromCache<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tmut: `mut` | undefined,\n): T {\n\ttarget.logger.info(`📖`, state.type, state.key, `reading cached value`)\n\tlet value = target.valueMap.get(state.key) as T\n\n\tconst mayNeedToBeCopied =\n\t\tmut === `mut` && state.type === `mutable_atom` && isChildStore(target)\n\tif (mayNeedToBeCopied) {\n\t\tconst mutableAtom = state\n\t\tconst { parent } = target\n\n\t\tif (target.valueMap.hasOwn(mutableAtom.key)) {\n\t\t\treturn value\n\t\t}\n\n\t\tconst parentValue = parent.valueMap.get(mutableAtom.key) as T &\n\t\t\tTransceiver<any, any, any>\n\n\t\ttarget.logger.info(`📃`, `atom`, mutableAtom.key, `copying`)\n\t\tconst jsonValue = parentValue.toJSON()\n\t\tconst copiedValue = mutableAtom.class.fromJSON(jsonValue)\n\t\ttarget.valueMap.set(mutableAtom.key, copiedValue)\n\t\tnew Tracker(mutableAtom, parent)\n\t\tvalue = copiedValue\n\t}\n\treturn value\n}\n\nexport function 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.getFrom(target)\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 { ViewOf } from \"atom.io\"\n\nimport type { ReadableState } from \"..\"\nimport { readFromCache, writeToCache } from \"../caching\"\nimport type { Store } from \"../store\"\n\nexport function readOrComputeValue<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tmut?: undefined,\n): ViewOf<T>\nexport function readOrComputeValue<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tmut: `mut`,\n): T\nexport function readOrComputeValue<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tmut: `mut` | undefined,\n): T {\n\tif (target.valueMap.has(state.key)) {\n\t\treturn readFromCache(target, state, mut)\n\t}\n\tconst { key } = state\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, key, `computing value`)\n\t\t\treturn state.getFrom(target)\n\t\tcase `atom`: {\n\t\t\tlet def: T\n\t\t\tif (state.default instanceof Function) {\n\t\t\t\tdef = state.default()\n\t\t\t} else {\n\t\t\t\tdef = state.default\n\t\t\t}\n\t\t\tconst cachedValue = writeToCache(target, state, def)\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\tdef,\n\t\t\t)\n\t\t\treturn cachedValue\n\t\t}\n\t\tcase `mutable_atom`: {\n\t\t\tconst instance = new state.class()\n\t\t\tconst cachedValue = writeToCache(target, state, instance)\n\t\t\ttarget.logger.info(\n\t\t\t\t`💁`,\n\t\t\t\t`mutable_atom`,\n\t\t\t\tstate.key,\n\t\t\t\t`could not find cached value; using default`,\n\t\t\t\tinstance,\n\t\t\t)\n\t\t\treturn cachedValue\n\t\t}\n\t}\n}\n","import type {\n\tMutableAtomToken,\n\tReadableToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type {\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadonlyPureSelectorFamily,\n\tRegularAtomFamily,\n\tWritableFamily,\n\tWritablePureSelectorFamily,\n} from \"..\"\nimport type { Transceiver } from \"../mutable\"\nimport { type Store, withdraw } from \"../store\"\n\nexport function getFamilyOfToken<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(store: Store, token: MutableAtomToken<T, K>): MutableAtomFamily<T, K>\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, K>,\n): RegularAtomFamily<T, K>\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, K>,\n): WritablePureSelectorFamily<T, K>\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, K>,\n): ReadonlyPureSelectorFamily<T, K>\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableToken<T, K>,\n): WritableFamily<T, K>\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K>,\n): ReadableFamily<T, K>\n\nexport function getFamilyOfToken(\n\tstore: Store,\n\ttoken: ReadableToken<any, any>,\n): ReadableFamily<any, any> {\n\treturn withdraw(store, {\n\t\t// biome-ignore lint/style/noNonNullAssertion: family is required\n\t\tkey: token.family!.key,\n\t\ttype: `${token.type}_family`,\n\t})\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.token.key,\n\t\t`Aborting transaction`,\n\t)\n\ttarget.parent.child = null\n}\n","import { type AtomIOToken, PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport { stringifyJson } from \"atom.io/json\"\n\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`${PRETTY_TOKEN_TYPES[token.type]} ${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 { Fn } from \"../utility-types\"\n\nexport function actUponStore<F extends Fn>(\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","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 {\n\tAtomToken,\n\tAtomUpdateEvent,\n\tStateUpdate,\n\tWritableToken,\n} from \"atom.io\"\n\nimport type { MutableAtom, WritableState } from \"..\"\nimport { hasRole } from \"../atom\"\nimport { readOrComputeValue } from \"../get-state\"\nimport type { Transceiver } from \"../mutable\"\nimport { isTransceiver } from \"../mutable\"\nimport type { OpenOperation } from \"../operation\"\nimport { deposit, type Store } from \"../store\"\nimport { isChildStore, isRootStore } from \"../transaction\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\n\nexport function dispatchOrDeferStateUpdate<T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tstate: WritableState<T>,\n\t[oldValue, newValue]: [T, T],\n\t_stateIsNewlyCreated: boolean,\n): void {\n\tconst { key, subject, type } = state\n\n\tconst update: StateUpdate<T> = {\n\t\toldValue: isTransceiver(oldValue) ? oldValue.READONLY_VIEW : oldValue,\n\t\tnewValue: isTransceiver(newValue) ? newValue.READONLY_VIEW : newValue,\n\t}\n\n\tif (isRootStore(target)) {\n\t\tswitch (type) {\n\t\t\tcase `mutable_atom`:\n\t\t\t\ttarget.logger.info(\n\t\t\t\t\t`📢`,\n\t\t\t\t\ttype,\n\t\t\t\t\tkey,\n\t\t\t\t\t`is now (`,\n\t\t\t\t\tnewValue,\n\t\t\t\t\t`) subscribers:`,\n\t\t\t\t\tsubject.subscribers,\n\t\t\t\t)\n\t\t\t\tbreak\n\t\t\tcase `atom`:\n\t\t\tcase `writable_pure_selector`:\n\t\t\tcase `writable_held_selector`:\n\t\t\t\ttarget.logger.info(\n\t\t\t\t\t`📢`,\n\t\t\t\t\ttype,\n\t\t\t\t\tkey,\n\t\t\t\t\t`went (`,\n\t\t\t\t\toldValue,\n\t\t\t\t\t`->`,\n\t\t\t\t\tnewValue,\n\t\t\t\t\t`) subscribers:`,\n\t\t\t\t\tsubject.subscribers,\n\t\t\t\t)\n\t\t}\n\t\tsubject.next(update)\n\t}\n\n\tif (isChildStore(target) && (type === `mutable_atom` || type === `atom`)) {\n\t\tif (target.on.transactionApplying.state === null) {\n\t\t\tconst token: WritableToken<T> = deposit(state)\n\n\t\t\tif (isTransceiver(newValue)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst { timestamp } = target.operation\n\t\t\tconst atomUpdate: AtomUpdateEvent<AtomToken<T>> = {\n\t\t\t\ttype: `atom_update`,\n\t\t\t\ttoken,\n\t\t\t\ttimestamp,\n\t\t\t\tupdate,\n\t\t\t}\n\t\t\ttarget.transactionMeta.update.subEvents.push(atomUpdate)\n\t\t\ttarget.logger.info(\n\t\t\t\t`📁`,\n\t\t\t\t`atom`,\n\t\t\t\tkey,\n\t\t\t\t`stowed (`,\n\t\t\t\toldValue,\n\t\t\t\t`->`,\n\t\t\t\tnewValue,\n\t\t\t\t`)`,\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tif (hasRole(state, `tracker:signal`)) {\n\t\t\tconst keyOfMutable = key.slice(1)\n\t\t\tconst mutable = target.atoms.get(keyOfMutable) as MutableAtom<\n\t\t\t\tTransceiver<unknown, any, any>\n\t\t\t>\n\t\t\tconst transceiver = readOrComputeValue(target, mutable, `mut`)\n\t\t\tconst accepted = transceiver.do(update.newValue) === null\n\t\t\tif (accepted === true) {\n\t\t\t\tevictDownstreamFromAtom(target, mutable)\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { Atom, OpenOperation, Store } from \"..\"\nimport { writeToCache } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport { markDone } from \"../operation\"\nimport { become } from \"./become\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\n\nexport const setAtom = <T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tatom: Atom<T>,\n\tnext: T | ((oldValue: T) => T),\n): [oldValue: T, newValue: T] => {\n\tconst oldValue = readOrComputeValue(target, atom, `mut`)\n\tlet newValue = become(next)(oldValue)\n\ttarget.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)\n\tnewValue = writeToCache(target, atom, newValue)\n\tmarkDone(target, atom.key)\n\tevictDownstreamFromAtom(target, atom)\n\treturn [oldValue, newValue]\n}\n","import type { Atom, OpenOperation, Store, WritableState } from \"..\"\nimport { traceRootSelectorAtoms } from \"..\"\nimport { dispatchOrDeferStateUpdate } from \"./dispatch-state-update\"\nimport { setAtom } from \"./set-atom\"\n\nfunction resetAtom<T>(\n\ttarget: Store & { operation: OpenOperation },\n\tatom: Atom<T>,\n): [oldValue: T, newValue: T] {\n\tswitch (atom.type) {\n\t\tcase `mutable_atom`:\n\t\t\treturn setAtom(target, atom, new atom.class())\n\t\tcase `atom`: {\n\t\t\tlet def = atom.default\n\t\t\tif (def instanceof Function) {\n\t\t\t\tdef = def()\n\t\t\t}\n\t\t\treturn setAtom(target, atom, def)\n\t\t}\n\t}\n}\n\nexport function resetAtomOrSelector<T>(\n\ttarget: Store & { operation: OpenOperation },\n\tstate: WritableState<T>,\n): [oldValue: T, newValue: T] {\n\tlet protoUpdate: [T, T]\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tprotoUpdate = resetAtom(target, 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 oldValue = state.getFrom(target)\n\t\t\t\tconst atoms = traceRootSelectorAtoms(target, state.key)\n\t\t\t\tfor (const atom of atoms.values()) {\n\t\t\t\t\tconst rootProtoUpdate = resetAtom(target, atom)\n\t\t\t\t\tdispatchOrDeferStateUpdate(target, state, rootProtoUpdate, false)\n\t\t\t\t}\n\t\t\t\tconst newValue = state.getFrom(target)\n\t\t\t\tprotoUpdate = [oldValue, newValue]\n\t\t\t}\n\t\t\tbreak\n\t}\n\n\treturn protoUpdate\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { operateOnStore, OWN_OP } from \"./operate-on-store\"\nimport type { RESET_STATE } from \"./reset-in-store\"\n\nexport function setIntoStore<T, New extends T>(\n\tstore: Store,\n\ttoken: WritableToken<T>,\n\tvalue: New | typeof RESET_STATE | ((oldValue: T) => New),\n): void\n\nexport function setIntoStore<\n\tT,\n\tK extends Canonical,\n\tNew extends T,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n\tvalue: New | typeof RESET_STATE | ((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 | typeof RESET_STATE | ((oldValue: T) => New),\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T>,\n\t\t\t\tvalue: New | typeof RESET_STATE | ((oldValue: T) => New),\n\t\t ]\n): void {\n\toperateOnStore(store, OWN_OP, ...params)\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { setIntoStore } from \"./set-into-store\"\n\nexport const RESET_STATE: unique symbol = Symbol(`RESET`)\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\tsetIntoStore(store, token, RESET_STATE)\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\tsetIntoStore(store, family, key, RESET_STATE)\n\t}\n}\n","import type { WritableSelector } from \"..\"\nimport { writeToCache } from \"../caching\"\nimport { markDone, type OpenOperation } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\n\nexport function setSelector<T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tselector: WritableSelector<T>,\n\tnext: T | ((oldValue: T) => T),\n): [oldValue: T, newValue: T] {\n\tlet oldValue: T\n\tlet newValue: T\n\tlet constant: T\n\n\tconst { type, key } = selector\n\n\tswitch (selector.type) {\n\t\tcase `writable_pure_selector`:\n\t\t\toldValue = selector.getFrom(target)\n\t\t\tnewValue = become(next)(oldValue)\n\t\t\twriteToCache(target, selector, newValue)\n\t\t\tbreak\n\t\tcase `writable_held_selector`:\n\t\t\tconstant = selector.const\n\t\t\tbecome(next)(constant)\n\t\t\toldValue = constant\n\t\t\tnewValue = constant\n\t}\n\n\ttarget.logger.info(`📝`, type, key, `setting to`, newValue)\n\tmarkDone(target, key)\n\tselector.setSelf(newValue)\n\treturn [oldValue, newValue]\n}\n","import type { WritableState } from \"..\"\nimport type { OpenOperation } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { setAtom } from \"./set-atom\"\nimport { setSelector } from \"./set-selector\"\n\nexport const setAtomOrSelector = <T>(\n\ttarget: Store & { operation: OpenOperation },\n\tstate: WritableState<T>,\n\tvalue: T | ((oldValue: T) => T),\n): [oldValue: T, newValue: T] => {\n\tlet protoUpdate: [T, T]\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tprotoUpdate = setAtom(target, state, value)\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\tprotoUpdate = setSelector(target, state, value)\n\t\t\tbreak\n\t}\n\n\treturn protoUpdate\n}\n","import type { AtomUpdateEvent } from \"atom.io\"\n\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\n\nexport function ingestAtomUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tatomUpdate: AtomUpdateEvent<any>,\n\tstore: Store,\n): void {\n\tconst {\n\t\ttoken,\n\t\tupdate: { newValue, oldValue },\n\t} = atomUpdate\n\tconst value = applying === `newValue` ? newValue : oldValue\n\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\tMoleculeCreationEvent,\n\tMoleculeDisposalEvent,\n\tMoleculeTransferEvent,\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: MoleculeCreationEvent = {\n\t\ttype: `molecule_creation`,\n\t\tkey,\n\t\tprovenance: origin,\n\t\ttimestamp: Date.now(),\n\t}\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.subEvents.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`key`,\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`key`,\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: MoleculeDisposalEvent = {\n\t\ttype: `molecule_disposal`,\n\t\tkey: molecule.key,\n\t\tvalues,\n\t\tprovenance,\n\t\ttimestamp: Date.now(),\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.subEvents.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`key`,\n\t\t\tstringKey,\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`key`,\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: MoleculeTransferEvent = {\n\t\ttype: `molecule_transfer`,\n\t\tkey: molecule.key,\n\t\texclusive: Boolean(exclusive),\n\t\tfrom: priorProvenance,\n\t\tto: [newProvenanceMolecule.key],\n\t\ttimestamp: Date.now(),\n\t}\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.subEvents.push(transferEvent)\n\t}\n\n\treturn claim\n}\n","import type {\n\tMoleculeCreationEvent,\n\tMoleculeDisposalEvent,\n\tMoleculeTransferEvent,\n\tReadableToken,\n\tStateCreationEvent,\n\tStateDisposalEvent,\n} from \"atom.io\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\n\nimport { disposeFromStore } from \"../families\"\nimport { mintInStore, MUST_CREATE } from \"../families/mint-in-store\"\nimport {\n\tallocateIntoStore,\n\tclaimWithinStore,\n\tdeallocateFromStore,\n} from \"../molecule\"\nimport type { Store } from \"../store\"\n\nexport function ingestCreationEvent(\n\tupdate: StateCreationEvent<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: StateDisposalEvent<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: StateCreationEvent<any> | StateDisposalEvent<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\tmintInStore(store, family, parseJson(familyMeta.subKey), MUST_CREATE)\n\t\t}\n\t}\n}\n\nexport function ingestMoleculeCreationEvent(\n\tupdate: MoleculeCreationEvent,\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: MoleculeDisposalEvent,\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\tmintInStore(store, family, update.key, MUST_CREATE)\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: MoleculeTransferEvent,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\t{\n\t\t\t\tfor (const newOwner of update.to) {\n\t\t\t\t\tclaimWithinStore<any, any, any>(\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tnewOwner,\n\t\t\t\t\t\tupdate.key,\n\t\t\t\t\t\tupdate.exclusive ? `exclusive` : undefined,\n\t\t\t\t\t)\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\tlet exclusivity: `exclusive` | undefined = `exclusive`\n\t\t\t\tfor (const previousOwner of update.from) {\n\t\t\t\t\tclaimWithinStore<any, any, any>(\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tpreviousOwner,\n\t\t\t\t\t\tupdate.key,\n\t\t\t\t\t\texclusivity,\n\t\t\t\t\t)\n\t\t\t\t\texclusivity = undefined\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t}\n}\n","import type {\n\tAtomOnly,\n\tAtomUpdateEvent,\n\tTimelineManageable,\n\tTimelineSelectorUpdateEvent,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\n\nexport function ingestSelectorUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tselectorUpdate: TimelineSelectorUpdateEvent<any>,\n\tstore: Store,\n): void {\n\tlet updates: AtomUpdateEvent<AtomOnly<TimelineManageable>>[]\n\tif (applying === `newValue`) {\n\t\tupdates = selectorUpdate.atomUpdates\n\t} else {\n\t\tupdates = selectorUpdate.atomUpdates.toReversed()\n\t}\n\tfor (const atomUpdate of updates) {\n\t\tingestAtomUpdate(applying, atomUpdate, store)\n\t}\n}\n","import type { TransactionOutcomeEvent } 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: TransactionOutcomeEvent<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? transactionUpdate.subEvents\n\t\t\t: [...transactionUpdate.subEvents].reverse()\n\tfor (const updateFromTransaction of updates) {\n\t\tswitch (updateFromTransaction.type) {\n\t\t\tcase `atom_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_outcome`:\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 { Fn } from \"../utility-types\"\nimport { isChildStore, isRootStore } from \"./is-root-store\"\nimport { setEpochNumberOfAction } from \"./set-epoch-number\"\n\nexport const applyTransaction = <F extends Fn>(\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 { subEvents: updates } = child.transactionMeta.update\n\tstore.logger.info(\n\t\t`🛄`,\n\t\t`transaction`,\n\t\tchild.transactionMeta.update.token.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.token.key,\n\t\t\tchild.transactionMeta.update.epoch,\n\t\t)\n\t\tconst myTransaction = withdraw<Fn>(store, {\n\t\t\tkey: child.transactionMeta.update.token.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.token.key,\n\t\t\t`Finished applying transaction.`,\n\t\t)\n\t} else if (isChildStore(parent)) {\n\t\tparent.transactionMeta.update.subEvents.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\tTransactionToken,\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 { Fn } 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\ttoken: TransactionToken<any>,\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, token.key)\n\tconst transactionMeta: TransactionProgress<Fn> = {\n\t\tphase: `building`,\n\t\tupdate: {\n\t\t\ttype: `transaction_outcome`,\n\t\t\ttoken,\n\t\t\tid,\n\t\t\tepoch: epoch === undefined ? Number.NaN : epoch + 1,\n\t\t\ttimestamp: Date.now(),\n\t\t\tsubEvents: [],\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: (t, identifier = arbitrary()) => actUponStore(child, t, identifier),\n\t\t\tfind: ((...ps: Parameters<typeof findState>) =>\n\t\t\t\tfindInStore(store, ...ps)) as typeof findState,\n\t\t\tjson: (t) => getJsonToken(child, t),\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\ttoken.key,\n\t\t`Building transaction with params:`,\n\t\tparams,\n\t)\n\treturn child\n}\n","import type {\n\tTransactionOptions,\n\tTransactionOutcomeEvent,\n\tTransactionToken,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { Fn } from \"../utility-types\"\nimport { abortTransaction } from \"./abort-transaction\"\nimport { applyTransaction } from \"./apply-transaction\"\nimport { buildTransaction } from \"./build-transaction\"\n\nexport type Transaction<F extends Fn> = {\n\tkey: string\n\ttype: `transaction`\n\tinstall: (store: Store) => void\n\tsubject: Subject<TransactionOutcomeEvent<TransactionToken<F>>>\n\trun: (parameters: Parameters<F>, id?: string) => ReturnType<F>\n}\n\nexport function createTransaction<F extends Fn>(\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 token = deposit(newTransaction)\n\t\t\tconst childStore = buildTransaction(store, token, 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 {\n\tActorToolkit,\n\tTransactionOutcomeEvent,\n\tTransactionToken,\n} from \"atom.io\"\n\nimport type { Junction } from \"../junction\"\nimport type { Fn } 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 Fn> = {\n\tphase: `applying` | `building`\n\tupdate: TransactionOutcomeEvent<TransactionToken<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\tReadableFamilyToken,\n\tReadableToken,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\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: Canonical,\n): ReadableToken<any> {\n\tconst family = withdraw(store, token)\n\tconst state = family(key)\n\n\treturn state\n}\n","import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { COUNTERFEIT, mint } from \"../store\"\nimport { isChildStore, isRootStore } from \"../transaction\"\nimport { initFamilyMemberInStore } from \"./init-family-member\"\n\nexport const MUST_CREATE: unique symbol = Symbol(`MUST_NOT_EXIST`)\n\nexport function mintInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\tfamilyToken: WritableFamilyToken<T, K>,\n\tkey: Key,\n\tinit?: typeof MUST_CREATE,\n): WritableToken<T, K>\nexport function mintInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n\tinit?: typeof MUST_CREATE,\n): ReadableToken<T, K>\nexport function mintInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n\tshouldCreate?: typeof MUST_CREATE,\n): ReadableToken<T, K> {\n\tlet stateToken: ReadableToken<T, K>\n\n\tlet willCreate: boolean\n\tswitch (shouldCreate) {\n\t\tcase MUST_CREATE:\n\t\t\twillCreate = true\n\t\t\tbreak\n\t\tcase undefined:\n\t\t\twillCreate = false\n\t\t\tbreak\n\t}\n\n\tconst stringKey = stringifyJson(key)\n\tconst molecule = store.molecules.get(stringKey)\n\tif (!molecule && store.config.lifespan === `immortal`) {\n\t\tconst fakeToken = mint(familyToken, key, COUNTERFEIT)\n\t\tstore.logger.warn(\n\t\t\t`💣`,\n\t\t\t`key`,\n\t\t\tstringKey,\n\t\t\t`was used to mint a counterfeit token for`,\n\t\t\tfamilyToken.type,\n\t\t\t`\"${familyToken.key}\"`,\n\t\t)\n\t\treturn fakeToken\n\t}\n\n\tif (willCreate) {\n\t\tstateToken = initFamilyMemberInStore(store, familyToken, key)\n\t\tconst target = newest(store)\n\t\tif (stateToken.family) {\n\t\t\tif (isRootStore(target)) {\n\t\t\t\tswitch (stateToken.type) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\tstore.on.atomCreation.next(stateToken)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\t\tcase `readonly_pure_selector`:\n\t\t\t\t\tcase `writable_held_selector`:\n\t\t\t\t\tcase `readonly_held_selector`:\n\t\t\t\t\t\tstore.on.selectorCreation.next(stateToken)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisChildStore(target) &&\n\t\t\t\ttarget.on.transactionApplying.state === null\n\t\t\t) {\n\t\t\t\ttarget.transactionMeta.update.subEvents.push({\n\t\t\t\t\ttype: `state_creation`,\n\t\t\t\t\ttoken: stateToken,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\tif (molecule) {\n\t\t\ttarget.moleculeData.set(stringKey, familyToken.key)\n\t\t}\n\t} else {\n\t\tstateToken = mint(familyToken, key)\n\t}\n\treturn stateToken\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { type Canonical, parseJson } from \"atom.io/json\"\n\nimport { seekInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { mintInStore, MUST_CREATE } from \"../families/mint-in-store\"\nimport type { OpenOperation } from \"../operation\"\nimport { closeOperation, openOperation } from \"../operation\"\nimport { type Store, withdraw } from \"../store\"\nimport { dispatchOrDeferStateUpdate } from \"./dispatch-state-update\"\nimport { resetAtomOrSelector } from \"./reset-atom-or-selector\"\nimport { RESET_STATE } from \"./reset-in-store\"\nimport { setAtomOrSelector } from \"./set-atom-or-selector\"\n\nexport const OWN_OP: unique symbol = Symbol(`OWN_OP`)\nexport const JOIN_OP: unique symbol = Symbol(`JOIN_OP`)\n\nexport function operateOnStore<T, New extends T>(\n\tstore: Store,\n\topMode: typeof JOIN_OP | typeof OWN_OP,\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 | typeof RESET_STATE | ((oldValue: T) => New),\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T>,\n\t\t\t\tvalue: New | typeof RESET_STATE | ((oldValue: T) => New),\n\t\t ]\n): void {\n\tlet existingToken: WritableToken<T> | undefined\n\tlet brandNewToken: WritableToken<T> | undefined\n\tlet token: WritableToken<T>\n\tlet family: WritableFamilyToken<T, Canonical> | null\n\tlet key: Canonical | null\n\tlet value: New | typeof RESET_STATE | ((oldValue: T) => New)\n\tif (params.length === 2) {\n\t\ttoken = params[0]\n\t\tvalue = params[1]\n\t\tif (`family` in token) {\n\t\t\tfamily = getFamilyOfToken(store, token)\n\t\t\tkey = parseJson(token.family.subKey)\n\t\t\texistingToken = seekInStore(store, family, key)\n\t\t\tif (!existingToken) {\n\t\t\t\tbrandNewToken = mintInStore(store, family, key, MUST_CREATE)\n\t\t\t\ttoken = brandNewToken\n\t\t\t} else {\n\t\t\t\ttoken = existingToken\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\tvalue = params[2]\n\t\texistingToken = seekInStore(store, family, key)\n\t\tif (!existingToken) {\n\t\t\tbrandNewToken = mintInStore(store, family, key, MUST_CREATE)\n\t\t\ttoken = brandNewToken\n\t\t} else {\n\t\t\ttoken = existingToken\n\t\t}\n\t}\n\n\tconst action = value === RESET_STATE ? `reset` : `set`\n\n\tlet target: Store & { operation: OpenOperation }\n\n\tif (opMode === OWN_OP) {\n\t\tconst result = openOperation(store, token)\n\t\tconst rejected = typeof result === `number`\n\t\tif (rejected) {\n\t\t\tconst rejectionTime = result\n\t\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t\t`waiting to ${action} \"${token.key}\" at T-${rejectionTime}`,\n\t\t\t\tfunction waitUntilOperationCloseToSetState() {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`🟢`,\n\t\t\t\t\t\ttoken.type,\n\t\t\t\t\t\ttoken.key,\n\t\t\t\t\t\t`resuming deferred`,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\t`from T-${rejectionTime}`,\n\t\t\t\t\t)\n\t\t\t\t\toperateOnStore(store, opMode, token, value)\n\t\t\t\t},\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\ttarget = result\n\t} else {\n\t\ttarget = store as Store & { operation: OpenOperation }\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`,\n\t\t\taction,\n\t\t\t`because key`,\n\t\t\tsubKey,\n\t\t\t`is not allocated.`,\n\t\t\tdisposal\n\t\t\t\t? `this key was previously disposed:${disposal.trace}`\n\t\t\t\t: `(no previous disposal trace found)`,\n\t\t)\n\t\treturn\n\t}\n\n\tconst state = withdraw(target, token)\n\tlet protoUpdate: [T, T]\n\tif (value === RESET_STATE) {\n\t\tprotoUpdate = resetAtomOrSelector(target, state)\n\t} else {\n\t\tprotoUpdate = setAtomOrSelector(target, state, value)\n\t}\n\tconst isNewlyCreated = Boolean(brandNewToken)\n\tdispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated)\n\n\tif (opMode === OWN_OP) {\n\t\tcloseOperation(target)\n\t}\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 function getSelectorDependencyKeys(\n\tstore: Store,\n\tkey: string,\n): (AtomKey<unknown> | ReadonlySelectorKey<unknown> | SelectorKey<unknown>)[] {\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 function 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 { ReadableToken } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { traceRootSelectorAtoms } from \"./trace-selector-atoms\"\n\nexport function 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: ReadableToken<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 { Canonical } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { getFallback } from \"../get-state/get-fallback\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport { reduceReference } from \"../get-state/reduce-reference\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { JOIN_OP, operateOnStore } from \"../set-state/operate-on-store\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { updateSelectorAtoms } from \"./update-selector-atoms\"\n\nexport function 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\treturn {\n\t\tget: (\n\t\t\t...params:\n\t\t\t\t| [ReadableFamilyToken<any, any>, Canonical]\n\t\t\t\t| [ReadableToken<any>]\n\t\t) => {\n\t\t\tconst target = newest(store)\n\t\t\tconst { token, familyToken, subKey } = reduceReference(store, ...params)\n\t\t\tlet dependencyValue: unknown\n\t\t\tif (`counterfeit` in token && familyToken && subKey) {\n\t\t\t\tconst dependencyFamily = withdraw(store, familyToken)\n\t\t\t\tdependencyValue = getFallback(store, token, dependencyFamily, subKey)\n\t\t\t} else {\n\t\t\t\tconst dependency = withdraw(store, token)\n\t\t\t\tdependencyValue = readOrComputeValue(store, dependency)\n\t\t\t}\n\n\t\t\tstore.logger.info(\n\t\t\t\t`🔌`,\n\t\t\t\tselectorType,\n\t\t\t\tselectorKey,\n\t\t\t\t`registers dependency ( \"${token.key}\" =`,\n\t\t\t\tdependencyValue,\n\t\t\t\t`)`,\n\t\t\t)\n\n\t\t\ttarget.selectorGraph.set(\n\t\t\t\t{\n\t\t\t\t\tupstreamSelectorKey: token.key,\n\t\t\t\t\tdownstreamSelectorKey: selectorKey,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tsource: token.key,\n\t\t\t\t},\n\t\t\t)\n\t\t\tupdateSelectorAtoms(store, selectorType, selectorKey, token, covered)\n\t\t\treturn dependencyValue\n\t\t},\n\t\tset: (<T, K extends Canonical, New extends T, Key extends K>(\n\t\t\t...params:\n\t\t\t\t| [\n\t\t\t\t\t\ttoken: WritableFamilyToken<T, K>,\n\t\t\t\t\t\tkey: Key,\n\t\t\t\t\t\tvalue: New | ((oldValue: any) => New),\n\t\t\t\t ]\n\t\t\t\t| [token: WritableToken<T>, value: New | ((oldValue: T) => New)]\n\t\t) => {\n\t\t\tconst target = newest(store)\n\t\t\toperateOnStore(target, JOIN_OP, ...params)\n\t\t}) as typeof setState,\n\t\tfind: ((...args: Parameters<typeof findState>) =>\n\t\t\tfindInStore(store, ...args)) as typeof findState,\n\t\tjson: (token) => getJsonToken(store, token),\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyHeldSelectorOptions,\n\tReadonlyHeldSelectorToken,\n} from \"atom.io\"\n\nimport type { ReadonlyHeldSelector } from \"..\"\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function 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\n\tconst getFrom = (innerTarget: 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\twriteToCache(innerTarget, readonlySelector, constant)\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\tgetFrom,\n\t\tinstall: (s: Store) => createReadonlyHeldSelector(s, options, family),\n\t}\n\tif (family) {\n\t\treadonlySelector.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 { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function 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\n\tconst getFrom = () => {\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 = writeToCache(innerTarget, readonlySelector, value)\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\tgetFrom,\n\t\tinstall: (s: Store) => createReadonlyPureSelector(s, options, family),\n\t}\n\tif (family) {\n\t\treadonlySelector.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 type {\n\tFamilyMetadata,\n\tWritableHeldSelectorOptions,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\n\nimport type { WritableHeldSelector } from \"..\"\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function 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 getFrom = (innerTarget: 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\toptions.get(getterToolkit, constant)\n\t\twriteToCache(innerTarget, mySelector, constant)\n\t\tstore.logger.info(`✨`, type, key, `=`, constant)\n\t\tcovered.clear()\n\t\treturn constant\n\t}\n\n\tconst setSelf = (): void => {\n\t\toptions.set(setterToolkit, constant)\n\t}\n\n\tconst mySelector: WritableHeldSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tgetFrom,\n\t\tsetSelf,\n\t\tinstall: (s: Store) => createWritableHeldSelector(s, options, family),\n\t}\n\tif (family) {\n\t\tmySelector.family = family\n\t}\n\ttarget.writableSelectors.set(key, mySelector)\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 { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function 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 getFrom = (innerTarget: 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 = options.get(getterToolkit)\n\t\tconst cached = writeToCache(innerTarget, mySelector, value)\n\t\tstore.logger.info(`✨`, type, key, `=`, cached)\n\t\tcovered.clear()\n\t\treturn cached\n\t}\n\n\tconst setSelf = (newValue: T): void => {\n\t\toptions.set(setterToolkit, newValue)\n\t}\n\n\tconst mySelector: WritablePureSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tgetFrom,\n\t\tsetSelf,\n\t\tinstall: (s: Store) => createWritablePureSelector(s, options, family),\n\t}\n\tif (family) mySelector.family = family\n\n\ttarget.writableSelectors.set(key, mySelector)\n\tconst initialValue = getFrom(target)\n\tstore.logger.info(`✨`, mySelector.type, mySelector.key, `=`, initialValue)\n\n\tconst token: WritablePureSelectorToken<T> = { key, type }\n\tif (family) token.family = family\n\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, family: familyMeta } = selectorToken\n\tif (!familyMeta) {\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(familyMeta.subKey)\n\t\tif (molecule) {\n\t\t\ttarget.moleculeData.delete(familyMeta.subKey, familyMeta.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: familyMeta.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\ttimestamp: Date.now(),\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: familyMeta.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\ttimestamp: Date.now(),\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: familyMeta.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\ttimestamp: Date.now(),\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: familyMeta.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\ttimestamp: Date.now(),\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\ttarget.moleculeData.delete(familyMeta.key, familyMeta.subKey)\n\t\tstore.logger.info(`🔥`, selectorToken.type, key, `deleted`)\n\t\tif (isChildStore(target) && target.transactionMeta.phase === `building`) {\n\t\t\ttarget.transactionMeta.update.subEvents.push({\n\t\t\t\ttype: `state_disposal`,\n\t\t\t\tsubType: `selector`,\n\t\t\t\ttoken: selectorToken,\n\t\t\t\ttimestamp: Date.now(),\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\tStateLifecycleEvent,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } 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\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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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\tStateLifecycleEvent<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, timestamp: Date.now() })\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\tStateLifecycleEvent,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport 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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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<StateLifecycleEvent<RegularAtomToken<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, timestamp: Date.now() })\n\t\treturn token\n\t}\n\n\tconst atomFamily = Object.assign(familyFunction, familyToken, {\n\t\tdefault: options.default,\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\tif (options.default instanceof Function === false) {\n\t\tstore.defaults.set(options.key, options.default)\n\t}\n\treturn familyToken\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyHeldSelectorFamilyOptions,\n\tReadonlyHeldSelectorFamilyToken,\n\tReadonlyHeldSelectorToken,\n\tStateLifecycleEvent,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ReadonlyHeldSelectorFamily } 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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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\tStateLifecycleEvent<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, timestamp: Date.now() })\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\tStateLifecycleEvent,\n\tWritableHeldSelectorFamilyOptions,\n\tWritableHeldSelectorFamilyToken,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport 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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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\tStateLifecycleEvent<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, timestamp: Date.now() })\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\tStateLifecycleEvent,\n\tWritablePureSelectorFamilyOptions,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } 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\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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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\tStateLifecycleEvent<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, timestamp: Date.now() })\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 } 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, any, any>,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, K>,\n\tkey: Key,\n): MutableAtomToken<T, 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 } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport { type Store, withdraw } from \"../store\"\nimport { mintInStore } from \"./mint-in-store\"\nimport { seekInStore } from \"./seek-in-store\"\n\n// seek [token 🟧] [inits ⬛]\n// find [token ✅] [inits ⬛]\n// mint [token ✅] [inits 🟧]\n// init [token ✅] [inits ✅]\n\nexport function findInStore<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\tfamilyToken: MutableAtomFamilyToken<T, K>,\n\tkey: Key,\n): MutableAtomToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T, K>\n\nexport function findInStore(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n): ReadableToken<any> {\n\twithdraw(store, familyToken)\n\tconst existingStateToken = seekInStore(store, familyToken, key)\n\tif (existingStateToken) {\n\t\treturn existingStateToken\n\t}\n\tconst newStateToken = mintInStore(store, familyToken, key)\n\treturn newStateToken\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, parseJson } from \"atom.io/json\"\n\nimport { seekInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { mintInStore, MUST_CREATE } from \"../families/mint-in-store\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\n\nexport function reduceReference<T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K>, key: K]\n\t\t| [token: ReadableToken<T>]\n): {\n\ttoken: ReadableToken<T>\n\tfamilyToken: ReadableFamilyToken<T, K> | undefined\n\tsubKey: K | undefined\n\tisNew: boolean\n} {\n\tlet existingToken: ReadableToken<T> | undefined\n\tlet brandNewToken: ReadableToken<T> | undefined\n\tlet familyToken: ReadableFamilyToken<T, K> | undefined\n\tlet subKey: K | undefined\n\tlet token: ReadableToken<T, K>\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t\tif (`family` in token) {\n\t\t\tfamilyToken = getFamilyOfToken(store, token)\n\t\t\twithdraw(store, familyToken)\n\t\t\tsubKey = parseJson(token.family.subKey)\n\t\t\texistingToken = seekInStore(store, familyToken, subKey)\n\t\t\tif (`counterfeit` in token) {\n\t\t\t\treturn {\n\t\t\t\t\ttoken,\n\t\t\t\t\tfamilyToken,\n\t\t\t\t\tsubKey,\n\t\t\t\t\tisNew: false,\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!existingToken) {\n\t\t\t\tbrandNewToken = mintInStore(store, familyToken, subKey, MUST_CREATE)\n\t\t\t\ttoken = brandNewToken\n\t\t\t} else {\n\t\t\t\ttoken = existingToken\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfamilyToken = params[0]\n\t\tsubKey = params[1]\n\t\texistingToken = seekInStore(store, familyToken, subKey)\n\t\tif (!existingToken) {\n\t\t\tbrandNewToken = mintInStore(store, familyToken, subKey, MUST_CREATE)\n\t\t\ttoken = brandNewToken\n\t\t} else {\n\t\t\ttoken = existingToken\n\t\t}\n\t}\n\n\treturn {\n\t\ttoken,\n\t\tfamilyToken,\n\t\tsubKey,\n\t\tisNew: Boolean(brandNewToken),\n\t}\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { type Store, withdraw } from \"../store\"\nimport { getFallback } from \"./get-fallback\"\nimport { readOrComputeValue } from \"./read-or-compute-value\"\nimport { reduceReference } from \"./reduce-reference\"\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\tconst { token, familyToken, subKey } = reduceReference(store, ...params)\n\n\tif (`counterfeit` in token && familyToken && subKey) {\n\t\tconst family = withdraw(store, familyToken)\n\t\treturn getFallback(store, token, family, subKey)\n\t}\n\tconst state = withdraw(store, token)\n\n\treturn readOrComputeValue(store, state)\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 { ReadableToken, StateUpdate, UpdateHandler } from \"atom.io\"\n\nimport { readOrComputeValue } from \"../get-state\"\nimport { reduceReference } from \"../get-state/reduce-reference\"\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\treduceReference(store, token)\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 {\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 } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tFn,\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, any, any>>(\n\tstore: Store,\n\ttoken: MutableAtomToken<T, any>,\n): MutableAtom<T>\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, any, any>,\n\tK extends Canonical,\n>(store: Store, token: MutableAtomFamilyToken<T, K>): MutableAtomFamily<T, 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 Fn>(\n\tstore: Store,\n\ttoken: TransactionToken<T>,\n): Transaction<T extends Fn ? 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 { TimelineEvent, TimelineManageable, TimelineToken } from \"atom.io\"\n\nimport type { Store } from \"../store/store\"\nimport { withdraw } from \"../store/withdraw\"\n\nexport const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(\n\tstore: Store,\n\ttoken: TimelineToken<ManagedAtom>,\n\tkey: string,\n\thandleUpdate: (update: TimelineEvent<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 { Fn, Store } from \"..\"\nimport { withdraw } from \"..\"\n\nexport const subscribeToTransaction = <F extends Fn>(\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 {\n\tReadableToken,\n\tTimelineEvent,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tTransactionUpdateHandler,\n\tUpdateHandler,\n} from \"atom.io\"\n\nimport { arbitrary } from \"../arbitrary\"\nimport type { Store } from \"../store\"\nimport type { Fn } from \"../utility-types\"\nimport { subscribeToState } from \"./subscribe-to-state\"\nimport { subscribeToTimeline } from \"./subscribe-to-timeline\"\nimport { subscribeToTransaction } from \"./subscribe-to-transaction\"\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 Fn>(\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: TimelineEvent<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: TimelineEvent<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","import type { FamilyMetadata, MutableAtomToken, RegularAtomToken } from \"atom.io\"\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 { SignalFrom, 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<T extends Transceiver<any, any, any>> {\n\tprivate initializeSignalAtom(\n\t\tmutableState: MutableAtomToken<T>,\n\t\tstore: Store,\n\t): RegularAtomToken<SignalFrom<T> | null> {\n\t\tconst latestSignalStateKey = `*${mutableState.key}`\n\t\tstore.atoms.delete(latestSignalStateKey)\n\t\tstore.valueMap.delete(latestSignalStateKey)\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 latestSignalState = createRegularAtom<SignalFrom<T> | null>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: latestSignalStateKey,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\tfamilyMetaData,\n\t\t\t[`tracker:signal`],\n\t\t)\n\t\tif (store.parent?.valueMap.has(latestSignalStateKey)) {\n\t\t\tconst parentValue = store.parent.valueMap.get(latestSignalStateKey)\n\t\t\tstore.valueMap.set(latestSignalStateKey, parentValue)\n\t\t}\n\n\t\treturn latestSignalState\n\t}\n\n\tprivate unsubscribeFromInnerValue!: () => void\n\tprivate unsubscribeFromState!: () => void\n\tprivate captureSignalsFromCore(\n\t\tmutableState: MutableAtomToken<T, any>,\n\t\tlatestSignalState: RegularAtomToken<SignalFrom<T> | null>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst stateKey = mutableState.key\n\t\tconst storeName = target.config.name\n\t\tconst storeStatus = isChildStore(target)\n\t\t\t? target.transactionMeta.update.token.key\n\t\t\t: `main`\n\t\tconst subscriptionKey = `tracker:${storeName}:${storeStatus}:${stateKey}`\n\t\tconst trackerCapturesOutboundSignal = (update: SignalFrom<T>) => {\n\t\t\tsetIntoStore(target, latestSignalState, update)\n\t\t}\n\t\tconst originalInnerValue = getFromStore(target, mutableState)\n\t\tthis.unsubscribeFromInnerValue = originalInnerValue.subscribe(\n\t\t\tsubscriptionKey,\n\t\t\ttrackerCapturesOutboundSignal,\n\t\t)\n\t\tthis.unsubscribeFromState = subscribeToState(\n\t\t\ttarget,\n\t\t\tmutableState,\n\t\t\tsubscriptionKey,\n\t\t\tfunction trackerLooksForNewReference(update: SignalFrom<T>) {\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\ttrackerCapturesOutboundSignal,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}.bind(this),\n\t\t)\n\t}\n\n\tprivate supplySignalsToCore(\n\t\tmutableState: MutableAtomToken<T>,\n\t\tlatestSignalState: RegularAtomToken<SignalFrom<T> | null>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst subscriptionKey = `tracker:${target.config.name}:${\n\t\t\tisChildStore(target) ? target.transactionMeta.update.token.key : `main`\n\t\t}:${mutableState.key}`\n\t\tsubscribeToState(\n\t\t\ttarget,\n\t\t\tlatestSignalState,\n\t\t\tsubscriptionKey,\n\t\t\tfunction trackerCapturesInboundSignal({ newValue, oldValue }) {\n\t\t\t\tconst timelineId = target.timelineTopics.getRelatedKey(\n\t\t\t\t\tlatestSignalState.key,\n\t\t\t\t)\n\n\t\t\t\tif (timelineId && target.timelines.get(timelineId)?.timeTraveling) {\n\t\t\t\t\tconst unsubscribe = subscribeToTimeline(\n\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t{ key: timelineId, type: `timeline` },\n\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\tfunction trackerWaitsForTimeTravelToFinish(update) {\n\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\tsetIntoStore(target, mutableState, (transceiver) => {\n\t\t\t\t\t\t\t\tif (update === `redo` && newValue) {\n\t\t\t\t\t\t\t\t\ttransceiver.do(newValue)\n\t\t\t\t\t\t\t\t} else if (update === `undo` && oldValue) {\n\t\t\t\t\t\t\t\t\ttransceiver.undo(oldValue)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn transceiver\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\treturn\n\t\t\t\t}\n\n\t\t\t\tconst mutable = getFromStore(target, mutableState)\n\t\t\t\tconst updateNumber = mutable.getUpdateNumber(newValue)\n\t\t\t\tconst eventOffset = updateNumber - mutable.cacheUpdateNumber\n\t\t\t\tif (newValue && eventOffset === 1) {\n\t\t\t\t\tsetIntoStore(\n\t\t\t\t\t\ttarget,\n\t\t\t\t\t\tmutableState,\n\t\t\t\t\t\t(transceiver) => (transceiver.do(newValue), transceiver),\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tconst expected = mutable.cacheUpdateNumber + 1\n\t\t\t\t\ttarget.logger.info(\n\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t`mutable_atom`,\n\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t`could not be updated. Expected update number`,\n\t\t\t\t\t\texpected,\n\t\t\t\t\t\t`but got`,\n\t\t\t\t\t\tupdateNumber,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n\n\tpublic mutableAtomToken: MutableAtomToken<T>\n\tpublic latestSignalToken: RegularAtomToken<SignalFrom<T> | null>\n\n\tpublic [Symbol.dispose]!: () => void\n\n\tpublic constructor(mutableAtomToken: MutableAtomToken<T>, store: Store) {\n\t\tconst target = newest(store)\n\t\tconst latestSignalToken = this.initializeSignalAtom(mutableAtomToken, target)\n\t\tthis.mutableAtomToken = mutableAtomToken\n\t\tthis.latestSignalToken = latestSignalToken\n\t\tthis.captureSignalsFromCore(mutableAtomToken, latestSignalToken, target)\n\t\tthis.supplySignalsToCore(mutableAtomToken, latestSignalToken, target)\n\t\ttarget.trackers.set(mutableAtomToken.key, this)\n\t\tthis[Symbol.dispose] = () => {\n\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\tthis.unsubscribeFromState()\n\t\t\ttarget.trackers.delete(mutableAtomToken.key)\n\t\t}\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\n\nimport type { MutableAtom } from \"..\"\nimport { createStandaloneSelector, 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<T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\toptions: MutableAtomOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): MutableAtomToken<T> {\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<{\n\t\tnewValue: T\n\t\toldValue: T\n\t}>()\n\tconst newAtom: MutableAtom<T> = {\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\tcreateStandaloneSelector(store, {\n\t\t\tkey: `${key}:JSON`,\n\t\t\tget: ({ get }) => get(token).toJSON(),\n\t\t\tset: ({ set }, newValue) => {\n\t\t\t\tset(token, options.class.fromJSON(newValue))\n\t\t\t},\n\t\t})\n\t}\n\tstore.on.atomCreation.next(token)\n\treturn token\n}\n","import type { MutableAtomToken, StateLifecycleEvent } from \"atom.io\"\nimport 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 { SignalFrom, Transceiver } from \"./transceiver\"\n\nexport class FamilyTracker<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n> {\n\tprivate trackers: Map<K, Tracker<T>> = new Map()\n\n\tpublic readonly latestSignalAtoms: RegularAtomFamily<SignalFrom<T> | null, K>\n\tpublic readonly mutableAtoms: MutableAtomFamily<T, K>\n\n\tpublic constructor(mutableAtoms: MutableAtomFamily<T, K>, store: Store) {\n\t\tconst latestSignalAtoms = createRegularAtomFamily<SignalFrom<T> | null, K>(\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.latestSignalAtoms = withdraw(store, latestSignalAtoms)\n\t\tthis.mutableAtoms = mutableAtoms\n\t\tconst trackerFamilyWatchesForCreationAndDisposalEvents = (\n\t\t\tevent: StateLifecycleEvent<MutableAtomToken<T>>,\n\t\t) => {\n\t\t\tconst { type, token } = event\n\t\t\tif (token.family) {\n\t\t\t\tconst key = parseJson(token.family.subKey)\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase `state_creation`:\n\t\t\t\t\t\tthis.trackers.set(key, new Tracker<T>(token, store))\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `state_disposal`: {\n\t\t\t\t\t\tconst tracker = this.trackers.get(key)\n\t\t\t\t\t\tif (tracker) {\n\t\t\t\t\t\t\ttracker[Symbol.dispose]()\n\t\t\t\t\t\t\tthis.trackers.delete(key)\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\tthis.mutableAtoms.subject.subscribe(\n\t\t\t`store=${store.config.name}::tracker-atom-family`,\n\t\t\ttrackerFamilyWatchesForCreationAndDisposalEvents,\n\t\t)\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tMutableAtomFamilyOptions,\n\tMutableAtomFamilyToken,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tStateLifecycleEvent,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createWritablePureSelectorFamily, type MutableAtomFamily } 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 { AsJSON, Transceiver } from \"./transceiver\"\n\nexport function createMutableAtomFamily<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\toptions: MutableAtomFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): MutableAtomFamilyToken<T, K> {\n\tconst familyToken: MutableAtomFamilyToken<T & Transceiver<any, any, any>, K> =\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `mutable_atom_family`,\n\t\t}\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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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<StateLifecycleEvent<MutableAtomToken<T>>>()\n\n\tconst familyFunction = (key: K): MutableAtomToken<T> => {\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> = {\n\t\t\tkey: fullKey,\n\t\t\tclass: options.class,\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, timestamp: Date.now() })\n\t\treturn token\n\t}\n\n\tconst atomFamily = Object.assign(familyFunction, familyToken, {\n\t\tclass: options.class,\n\t\tsubject,\n\t\tinstall: (s: Store) => createMutableAtomFamily(s, options),\n\t\tinternalRoles,\n\t}) satisfies MutableAtomFamily<T, K>\n\n\tstore.families.set(options.key, atomFamily)\n\n\tcreateWritablePureSelectorFamily<AsJSON<T>, K>(\n\t\tstore,\n\t\t{\n\t\t\tkey: `${options.key}:JSON`,\n\t\t\tget:\n\t\t\t\t(key) =>\n\t\t\t\t({ get }) =>\n\t\t\t\t\tget(familyToken, key).toJSON(),\n\t\t\tset:\n\t\t\t\t(key) =>\n\t\t\t\t({ set }, newValue) => {\n\t\t\t\t\tset(familyToken, key, options.class.fromJSON(newValue))\n\t\t\t\t},\n\t\t},\n\t\t[`mutable`, `json`],\n\t)\n\n\tnew FamilyTracker(atomFamily, store)\n\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<any, Json.Serializable, Json.Serializable>,\n\tKey extends Canonical,\n>(\n\tmutableAtomFamily: MutableAtomFamilyToken<Core, Key>,\n\tstore: Store,\n): WritablePureSelectorFamily<ReturnType<Core[`toJSON`]>, Key> => {\n\tconst target = newest(store)\n\tconst key = `${mutableAtomFamily.key}:JSON`\n\tconst jsonFamily = target.families.get(key) as WritablePureSelectorFamily<\n\t\tReturnType<Core[`toJSON`]>,\n\t\tKey\n\t>\n\treturn jsonFamily\n}\n","import type {\n\tMutableAtomToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport { parseJson } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { newest } from \"../lineage\"\nimport { type Store, withdraw } from \"../store\"\nimport type { AsJSON, Transceiver } from \"./transceiver\"\n\nexport const getJsonToken = <T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\tmutableAtomToken: MutableAtomToken<T>,\n): WritablePureSelectorToken<AsJSON<T>> => {\n\tif (mutableAtomToken.family) {\n\t\tconst target = newest(store)\n\t\tconst jsonFamilyKey = `${mutableAtomToken.family.key}:JSON`\n\t\tconst jsonFamilyToken: WritablePureSelectorFamilyToken<AsJSON<T>, string> = {\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 = parseJson(mutableAtomToken.family.subKey)\n\t\tconst jsonToken = findInStore(store, family, subKey)\n\t\treturn jsonToken\n\t}\n\tconst token: WritablePureSelectorToken<AsJSON<T>> = {\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 { SignalFrom, Transceiver } from \"./transceiver\"\n\nexport const getUpdateFamily = <\n\tT extends Transceiver<any, Json.Serializable, Json.Serializable>,\n\tK extends string,\n>(\n\tmutableAtomFamily: MutableAtomFamilyToken<T, K>,\n\tstore: Store,\n): AtomFamily<SignalFrom<T>, K> => {\n\tconst target = newest(store)\n\tconst key = `*${mutableAtomFamily.key}`\n\tconst updateFamily: AtomFamily<SignalFrom<T>, K> = target.families.get(\n\t\tkey,\n\t) as AtomFamily<SignalFrom<T>, K>\n\treturn updateFamily\n}\n","import type { MutableAtomToken, RegularAtomToken } from \"atom.io\"\n\nimport type { SignalFrom, Transceiver } from \"./transceiver\"\n\nexport const getUpdateToken = <T extends Transceiver<any, any, any>>(\n\tmutableAtomToken: MutableAtomToken<T>,\n): RegularAtomToken<SignalFrom<T>> => {\n\tconst key = `*${mutableAtomToken.key}`\n\tconst updateToken: RegularAtomToken<SignalFrom<T>> = { 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<\n\tV,\n\tS extends Json.Serializable,\n\tJ extends Json.Serializable,\n> {\n\tREADONLY_VIEW: V\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\ttoJSON: () => J\n}\n\n// biome-ignore format: intersection\nexport type TransceiverConstructor<\n J extends Json.Serializable,\n T extends Transceiver<any, any, J>\n> =\n\t& ( new () => T )\n\t& { fromJSON: (json: J) => T }\n\nexport function isTransceiver(\n\tvalue: unknown,\n): value is Transceiver<any, Json.Serializable, 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\t`cacheUpdateNumber` in value &&\n\t\t`getUpdateNumber` in value &&\n\t\t`READONLY_VIEW` in value &&\n\t\t`toJSON` in value\n\t)\n}\n\nexport type TransceiverMode = `playback` | `record` | `transaction`\n\nexport type SignalFrom<T extends Transceiver<any, any, any>> =\n\tT extends Transceiver<any, infer S, any> ? S : never\n\nexport type AsJSON<T extends Transceiver<any, any, any>> = T extends Transceiver<\n\tany,\n\tany,\n\tinfer J\n>\n\t? J\n\t: never\n\nexport type ConstructorOf<T extends Transceiver<any, any, any>> =\n\tTransceiverConstructor<AsJSON<T>, T>\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\"`]\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\n// The function wants a constructor C\n// - that has a static fromJSON(json) returning an instance of C\n// - and whose instances have toJSON() whose return type matches fromJSON's param\n","import type {\n\tAtomToken,\n\tLogger,\n\tMoleculeCreationEvent,\n\tMoleculeDisposalEvent,\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 { Fn } 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, any, any>>> = new Map()\n\tpublic families: Map<\n\t\tstring,\n\t\t| HeldSelectorFamily<any, any>\n\t\t| MutableAtomFamily<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<Fn>> = new Map()\n\tpublic transactionMeta: TransactionEpoch | TransactionProgress<Fn> = {\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<Fn>>\n\ttransactionApplying: StatefulSubject<TransactionProgress<Fn> | null>\n\toperationClose: Subject<OperationProgress>\n\tmoleculeCreation: Subject<MoleculeCreationEvent>\n\tmoleculeDisposal: Subject<MoleculeDisposalEvent>\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\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\"\nimport type { internalRole } from \"./has-role\"\n\nexport function createRegularAtom<T>(\n\tstore: Store,\n\toptions: RegularAtomOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tinternalRoles?: internalRole[],\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\tif (internalRoles) {\n\t\tnewAtom.internalRoles = internalRoles\n\t}\n\ttarget.atoms.set(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\tstore.on.atomCreation.next(token)\n\treturn token\n}\n","import type { AtomDisposalEvent, AtomToken, StateLifecycleEvent } from \"atom.io\"\n\nimport type { Store, Subject } from \"..\"\nimport { getUpdateToken, isChildStore, newest, withdraw } from \"..\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\n\nexport function disposeAtom(store: Store, atomToken: AtomToken<any>): 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 familyToken = getFamilyOfToken(store, atomToken)\n\t\tconst atomFamily = withdraw(store, familyToken)\n\t\tconst subject = atomFamily.subject as Subject<\n\t\t\tStateLifecycleEvent<AtomToken<any>>\n\t\t>\n\n\t\tconst disposal: AtomDisposalEvent<AtomToken<any>> = {\n\t\t\ttype: `state_disposal`,\n\t\t\tsubType: `atom`,\n\t\t\ttoken: atomToken,\n\t\t\tvalue: lastValue,\n\t\t\ttimestamp: Date.now(),\n\t\t}\n\n\t\tsubject.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\ttarget.moleculeData.delete(family.key, family.subKey)\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.subEvents.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.subEvents.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 { Atom } from \"..\"\n\nexport const INTERNAL_ROLES = [`tracker:signal`] as const\nexport type internalRole = (typeof INTERNAL_ROLES)[number]\n\nexport function hasRole(atom: Atom<any>, role: internalRole): boolean {\n\tif (`internalRoles` in atom === false) {\n\t\treturn false\n\t}\n\n\treturn atom.internalRoles.includes(role)\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 { 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.token.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.token.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 {\n\tCompoundTypedKey,\n\tfindState,\n\tgetState,\n\tJoinOptions,\n\tMutableAtomFamilyToken,\n\tRead,\n\tReadonlyPureSelectorFamilyToken,\n\tRegularAtomFamilyToken,\n\tsetState,\n\tViewOf,\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 { 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<SetRTX<string>, string>\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<SetRTX<string>, string>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tclass: SetRTX,\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) => ViewOf<Content> | null> = (\n\t\t\t\t{ get },\n\t\t\t\tkey,\n\t\t\t) => get(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, ViewOf<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, ViewOf<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 { JoinOptions, JoinToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { Join } from \"./join-internal\"\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 { 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 } 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>, 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\tAtomUpdateEvent,\n\tStateCreationEvent,\n\tStateDisposalEvent,\n\tTimelineEvent,\n\tTimelineManageable,\n\tTimelineOptions,\n\tTimelineToken,\n\tTransactionOutcomeEvent,\n\tTransactionSubEvent,\n\tTransactionToken,\n} from \"atom.io\"\n\nimport { reduceReference } from \"../get-state/reduce-reference\"\nimport { newest } from \"../lineage\"\nimport { getUpdateToken } from \"../mutable\"\nimport { deposit, type Store, withdraw } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { isChildStore } from \"../transaction\"\n\nexport type Timeline<ManagedAtom extends TimelineManageable> = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\tshouldCapture?: (\n\t\tupdate: TimelineEvent<ManagedAtom>,\n\t\ttimeline: Timeline<ManagedAtom>,\n\t) => boolean\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineEvent<ManagedAtom>[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: Store) => void\n\tsubject: Subject<TimelineEvent<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\treduceReference(store, atomToken)\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 currentSelectorToken =\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\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.timestamp\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.token.key}\"`\n\t\t\t\t\t\t: currentSelectorToken\n\t\t\t\t\t\t\t? `in selector \"${currentSelectorToken.key}\"`\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 (currentSelectorToken && currentSelectorTime) {\n\t\t\t\t\t\tlet latestUpdate: TimelineEvent<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\t// key: currentSelectorKey,\n\t\t\t\t\t\t\t\ttoken: currentSelectorToken,\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\ttype: `atom_update`,\n\t\t\t\t\t\t\t\ttoken: atomToken,\n\t\t\t\t\t\t\t\tupdate,\n\t\t\t\t\t\t\t\ttimestamp: Date.now(), // 👺 use store operation\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 \"${currentSelectorToken.key}\" with`,\n\t\t\t\t\t\t\t\tlatestUpdate.atomUpdates.map(\n\t\t\t\t\t\t\t\t\t(atomUpdate) => atomUpdate.token.key,\n\t\t\t\t\t\t\t\t),\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\ttype: `atom_update`,\n\t\t\t\t\t\t\t\t\ttoken: atomToken,\n\t\t\t\t\t\t\t\t\tupdate,\n\t\t\t\t\t\t\t\t\ttimestamp: Date.now(), // 👺 use store operation\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 \"${currentSelectorToken.key}\" to`,\n\t\t\t\t\t\t\t\t\tlatestUpdate?.atomUpdates.map(\n\t\t\t\t\t\t\t\t\t\t(atomUpdate) => atomUpdate.token.key,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\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: AtomUpdateEvent<any> = {\n\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\ttoken: deposit(atom),\n\t\t\t\t\t\t\tupdate,\n\t\t\t\t\t\t\ttimestamp,\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: TransactionOutcomeEvent<TransactionToken<any>>,\n) {\n\tconst currentTxKey = txUpdateInProgress.token.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 subEventsFiltered = filterTransactionSubEvents(\n\t\t\t\t\t\ttransactionUpdate.subEvents,\n\t\t\t\t\t\ttimelineTopics,\n\t\t\t\t\t)\n\n\t\t\t\t\tconst timelineTransactionUpdate: TransactionOutcomeEvent<\n\t\t\t\t\t\tTransactionToken<any>\n\t\t\t\t\t> = {\n\t\t\t\t\t\t...transactionUpdate,\n\t\t\t\t\t\tsubEvents: subEventsFiltered,\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 filterTransactionSubEvents(\n\tupdates: TransactionSubEvent[],\n\ttimelineTopics: Set<string>,\n): TransactionSubEvent[] {\n\treturn updates\n\t\t.filter((updateFromTx) => {\n\t\t\tif (updateFromTx.type === `transaction_outcome`) {\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 `atom_update`:\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}\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): TransactionSubEvent => {\n\t\t\tif (`subEvents` in updateFromTx) {\n\t\t\t\treturn {\n\t\t\t\t\t...updateFromTx,\n\t\t\t\t\tsubEvents: filterTransactionSubEvents(\n\t\t\t\t\t\tupdateFromTx.subEvents,\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: StateCreationEvent<any> | StateDisposalEvent<any>,\n\ttl: Timeline<any>,\n): void {\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(event)\n\t\t\t\ttl.at = tl.history.length\n\t\t\t\ttl.subject.next(event)\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_outcome`: {\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,UAAU,SAAuB,KAAK,QAAgB;AACrE,QAAO,SAAS,SAAS,IAAI,MAAM;AACnC;;;;ACID,SAAgB,OAA0B,OAAa;AACtD,QAAO,MAAM,UAAU,KACtB,SAAQ,MAAM;AAEf,QAAO;AACP;;;;ACXD,IAAa,iBAAb,MAAa,eAAkB;CAC9B,AAAU;CACV,AAAU,SAAS;CAGnB,AAAO,YAAY,eAA6B;EAC/C,IAAIA;AACJ,MAAI,OAAO,kBAAkB,SAC5B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,MACA,YACA,MAAM,KACN,aAAa,OAAO,UACnB,WAAW,SAAS,QAAQ,YAC5B,gBAAgB,MAAM,IAAI,yBAAyB,OAAO;AAE5D;CACA;AAED,cAAa,gBAAgB,WAAW,SAAS,gBAAgB;AACjE,KAAI,WAAW,OACd,GAAE,aAAa;CAGhB,MAAM,SAAS,aAAa,QAAQ,aAAa;CACjD,MAAM,WAAW,WAAW,SAAS,aAAa;AAElD,SAAQ,OAAO,MAAf;EACC,KAAK;AACJ,oBAAiB,UAAU,QAAQ;AACnC;EAED,KAAK;AACJ,wBAAqB,UAAU,QAAQ;AACvC;EAED,KAAK;AACJ,2BAAwB,UAAU,QAAQ;AAC1C;EAED,KAAK;AACJ,uBAAoB,QAAQ,UAAU;AACtC;EAED,KAAK;AACJ,uBAAoB,QAAQ,UAAU;AACtC;EAED,KAAK;EACL,KAAK;CACL;AAED,KAAI,WAAW,OACd,GAAE,aAAa;AAGhB,cAAa,QAAQ,KAAK;AAC1B,cAAa,gBAAgB;AAC7B,OAAM,OAAO,KACZ,MACA,YACA,MAAM,KACN,IAAI,MAAM,IAAI,cAAc,aAAa,GAAG,KAAK,aAAa,QAAQ;AAEvE"}
1
+ {"version":3,"file":"index.js","names":["length: number","COUNTERFEIT: unique symbol","stateToken: ReadableToken<any> & {\n\t\tcounterfeit?: boolean\n\t}","a: AType | undefined","b: BType | undefined","a: AType","b: BType","content: Content | undefined","singleRelation: AType | BType | undefined","superResolve: ((value: T) => void) | undefined","superReject: ((reason?: any) => void) | undefined","mutableAtom","def: T","update: StateUpdate<T>","token: WritableToken<T>","atomUpdate: AtomUpdateEvent<AtomToken<T>>","protoUpdate: [T, T]","RESET_STATE: unique symbol","token: WritableToken<T>","family: WritableFamilyToken<T, Canonical> | null","key: Canonical | null","oldValue: T","newValue: T","constant: T","protoUpdate: [T, T]","invalidKeys: stringified<Canonical>[]","creationEvent: MoleculeCreationEvent","compoundKey: CompoundTypedKey<T, A, B>","join","provenance: stringified<Canonical>[]","values: [string, any][]","disposalEvent: MoleculeDisposalEvent","transferEvent: MoleculeTransferEvent","exclusivity: `exclusive` | undefined","updates: AtomUpdateEvent<AtomOnly<TimelineManageable>>[]","childBase: Omit<ChildStore, `transactionMeta`>","transactionMeta: TransactionProgress<Fn>","child: ChildStore","newTransaction: Transaction<F>","token","target","MUST_CREATE: unique symbol","stateToken: ReadableToken<T, K>","willCreate: boolean","OWN_OP: unique symbol","JOIN_OP: unique symbol","existingToken: WritableToken<T> | undefined","brandNewToken: WritableToken<T> | undefined","token: WritableToken<T>","family: WritableFamilyToken<T, Canonical> | null","key: Canonical | null","value: New | typeof RESET_STATE | ((oldValue: T) => New)","target: Store & { operation: OpenOperation }","protoUpdate: [T, T]","dependencyValue: unknown","readonlySelector: ReadonlyHeldSelector<T>","token: ReadonlyHeldSelectorToken<T>","readonlySelector: ReadonlyPureSelector<T>","token: ReadonlyPureSelectorToken<T>","mySelector: WritableHeldSelector<T>","token: WritableHeldSelectorToken<T>","mySelector: WritablePureSelector<T>","token: WritablePureSelectorToken<T>","state","familyToken: SelectorFamilyToken<any, any>","family: FamilyMetadata","family: FamilyMetadata","individualOptions: RegularAtomOptions<T>","atomFamily","family: FamilyMetadata","family: FamilyMetadata","selectorFamily","family: FamilyMetadata","selectorFamily","state: Molecule<any> | ReadableState<any> | undefined","token: ReadableToken<any>","existingToken: ReadableToken<T> | undefined","brandNewToken: ReadableToken<T> | undefined","familyToken: ReadableFamilyToken<T, K> | undefined","subKey: K | undefined","token: ReadableToken<T, K>","unsubscribe","updateHandler: UpdateHandler<T>","withdrawn: AtomIOInternalResource | undefined","target: Store | null","familyMetaData: FamilyMetadata | undefined","newAtom: MutableAtom<T>","cleanupFunctions: (() => void)[]","familyToken: MutableAtomFamilyToken<T & Transceiver<any, any, any>, K>","family: FamilyMetadata","individualOptions: MutableAtomOptions<T>","atomFamily","jsonFamilyToken: WritablePureSelectorFamilyToken<AsJSON<T>, string>","token: WritablePureSelectorToken<AsJSON<T>>","updateFamily: AtomFamily<SignalFrom<T>, K>","updateToken: RegularAtomToken<SignalFrom<T>>","IMPLICIT: { readonly STORE: Store }","newAtom: RegularAtom<T>","cleanupFunctions: (() => void)[]","atomFamily","disposal: AtomDisposalEvent<AtomToken<any>>","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) => ViewOf<Content> | null>","setContent: Write<(key: string, content: Content) => void>","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>","relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>","tl: Timeline<ManagedAtom>","atomToken: AtomToken<ManagedAtom>","familyToken: AtomFamilyToken<any, any>","token: TimelineToken<ManagedAtom>","latestUpdate: TimelineEvent<any> | undefined","atomUpdate: AtomUpdateEvent<any>","currentTxToken: TransactionToken<any>","timelineTransactionUpdate: TransactionOutcomeEvent<\n\t\t\t\t\t\tTransactionToken<any>\n\t\t\t\t\t>","key: string","familyKey: string | undefined"],"sources":["../../src/internal/arbitrary.ts","../../src/internal/lineage.ts","../../src/internal/store/circular-buffer.ts","../../src/internal/store/deposit.ts","../../src/internal/store/mint-or-counterfeit.ts","../../src/internal/junction.ts","../../src/internal/subject.ts","../../src/internal/subscribe/recall-state.ts","../../src/internal/get-state/get-fallback.ts","../../src/internal/future.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/families/get-family-of-token.ts","../../src/internal/transaction/abort-transaction.ts","../../src/internal/not-found-error.ts","../../src/internal/transaction/act-upon-store.ts","../../src/internal/set-state/become.ts","../../src/internal/set-state/dispatch-state-update.ts","../../src/internal/set-state/set-atom.ts","../../src/internal/set-state/reset-atom-or-selector.ts","../../src/internal/set-state/set-into-store.ts","../../src/internal/set-state/reset-in-store.ts","../../src/internal/set-state/set-selector.ts","../../src/internal/set-state/set-atom-or-selector.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/families/init-family-member.ts","../../src/internal/families/mint-in-store.ts","../../src/internal/set-state/operate-on-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/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/seek-in-store.ts","../../src/internal/families/find-in-store.ts","../../src/internal/families/dispose-from-store.ts","../../src/internal/get-state/reduce-reference.ts","../../src/internal/get-state/get-from-store.ts","../../src/internal/subscribe/subscribe-to-root-atoms.ts","../../src/internal/subscribe/subscribe-to-state.ts","../../src/internal/store/withdraw.ts","../../src/internal/subscribe/subscribe-to-timeline.ts","../../src/internal/subscribe/subscribe-to-transaction.ts","../../src/internal/subscribe/subscribe-in-store.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/atom/create-regular-atom.ts","../../src/internal/atom/dispose-atom.ts","../../src/internal/atom/has-role.ts","../../src/internal/capitalize.ts","../../src/internal/install-into-store.ts","../../src/internal/join/join-internal.ts","../../src/internal/join/create-join.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\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 } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tFn,\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, any, any>>(\n\tstate: MutableAtom<T>,\n): MutableAtomToken<T>\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, any, any>,\n\tK extends Canonical,\n>(state: MutableAtomFamily<T, K>): MutableAtomFamilyToken<T, 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 Fn>(state: Transaction<T>): 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 {\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 } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\n\nexport const COUNTERFEIT: unique symbol = Symbol(`counterfeit`)\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 mint<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n\tKey extends K,\n>(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): RegularAtomToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): AtomToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: WritablePureSelectorFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): WritablePureSelectorToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): ReadonlyPureSelectorToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): SelectorToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): WritableToken<T>\n\nexport function mint<T, K extends Canonical, Key extends K>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n\tcounterfeit?: typeof COUNTERFEIT,\n): ReadableToken<T>\n\nexport function mint(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n\tcounterfeit?: typeof COUNTERFEIT,\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: ReadableToken<any> & {\n\t\tcounterfeit?: boolean\n\t} = {\n\t\tkey: fullKey,\n\t\ttype,\n\t\tfamily: {\n\t\t\tkey: token.key,\n\t\t\tsubKey,\n\t\t},\n\t}\n\n\tif (counterfeit) {\n\t\tstateToken.counterfeit = true\n\t}\n\n\treturn stateToken\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 { ReadableToken } from \"atom.io\"\nimport { type Canonical, stringifyJson } from \"atom.io/json\"\n\nimport type { ReadableFamily } from \"..\"\nimport type { Store } from \"../store\"\n\nexport function getFallback<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K>,\n\tfamily: ReadableFamily<T, K>,\n\tsubKey: K,\n): T {\n\tconst disposal = store.disposalTraces.buffer.find(\n\t\t(item) => item?.key === stringifyJson(subKey),\n\t)\n\tstore.logger.error(\n\t\t`❌`,\n\t\ttoken.type,\n\t\ttoken.key,\n\t\t`gets a fallback value because key`,\n\t\tsubKey,\n\t\t`is not allocated`,\n\t\tdisposal\n\t\t\t? `This key was previously disposed:\\n${disposal.trace}`\n\t\t\t: `(no previous disposal trace found)`,\n\t)\n\tswitch (family.type) {\n\t\tcase `mutable_atom_family`: {\n\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\t}\n\t\t\tconst defaultValue = new family.class()\n\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\treturn defaultValue\n\t\t}\n\t\tcase `atom_family`: {\n\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\t}\n\t\t\tconst def = family.default as (key: K) => T\n\t\t\tconst defaultValue = def(subKey)\n\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\treturn defaultValue\n\t\t}\n\t\tcase `readonly_pure_selector_family`:\n\t\tcase `writable_pure_selector_family`:\n\t\tcase `readonly_held_selector_family`:\n\t\tcase `writable_held_selector_family`: {\n\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\t}\n\t\t\tconst defaultValue = family.default(subKey)\n\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\treturn defaultValue\n\t\t}\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 { LazyMap } from \"../lazy-map\"\nimport type { Store } from \"../store\"\nimport type { Fn } 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<Fn>\n\tparent: ChildStore | RootStore\n\tchild: ChildStore | null\n\tvalueMap: LazyMap<string, any>\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| OpenOperation<any>\n\t| {\n\t\t\topen: false\n\t }\nexport type OpenOperation<R extends ReadableToken<any> = ReadableToken<any>> = {\n\topen: true\n\ttoken: R\n\tdone: Set<string>\n\tprev: Map<string, any>\n\ttimestamp: number\n}\n\nexport function openOperation(\n\tstore: Store,\n\ttoken: ReadableToken<any>,\n): number | (Store & { operation: OpenOperation }) {\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\ttimestamp: 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\tisChildStore(store)\n\t\t\t\t? ` ${store.transactionMeta.phase} \"${store.transactionMeta.update.token.key}\"`\n\t\t\t\t: ``\n\t\t}`,\n\t)\n\treturn store as Store & { operation: OpenOperation }\n}\n\nexport function 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 } from \"..\"\nimport { evictCachedValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Store } from \"../store\"\n\nexport function evictDownstreamFromAtom(store: Store, atom: Atom<any>): void {\n\tconst target = newest(store)\n\tconst { key, type } = atom\n\tconst downstreamKeys = target.selectorAtoms.getRelatedKeys(key)\n\ttarget.logger.info(\n\t\t`🧹`,\n\t\ttype,\n\t\tkey,\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\ttype,\n\t\t\t\tkey,\n\t\t\t\t`[ ${[...target.operation.done].join(`, `)} ] already done`,\n\t\t\t)\n\t\t}\n\t\tfor (const downstreamKey of downstreamKeys) {\n\t\t\tif (isDone(target, downstreamKey)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tevictCachedValue(target, downstreamKey)\n\t\t\tmarkDone(target, downstreamKey)\n\t\t}\n\t}\n}\n\nexport function evictDownstreamFromSelector(\n\tstore: Store,\n\tselectorKey: string,\n): void {\n\tconst target = newest(store)\n\tconst relationEntries = target.selectorGraph\n\t\t.getRelationEntries({\n\t\t\tupstreamSelectorKey: selectorKey,\n\t\t})\n\t\t.filter(([_, { source }]) => source === selectorKey)\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\tevictDownstreamFromSelector(store, downstreamSelectorKey)\n\t}\n}\n","import type { ReadableState, Transceiver } from \".\"\nimport { closeOperation, isChildStore, openOperation, Tracker } from \".\"\nimport { Future } from \"./future\"\nimport {\n\tevictDownstreamFromAtom,\n\tevictDownstreamFromSelector,\n} from \"./set-state/evict-downstream\"\nimport type { Store } from \"./store\"\n\nexport function writeToCache<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tvalue: T,\n\t// subject: Subject<StateUpdate<unknown>>,\n): T\nexport function writeToCache<T extends Promise<any>>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tvalue: T,\n\t// subject: Subject<StateUpdate<unknown>>,\n): Future<Awaited<T>>\nexport function writeToCache<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tvalue: T,\n\t// subject: Subject<StateUpdate<unknown>>,\n): Future<T> | T {\n\tconst { key, subject, type } = state\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\topenOperation(target, state)\n\t\t\t\t\twriteToCache(target, state, resolved)\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase `atom`:\n\t\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\t\tevictDownstreamFromAtom(target, state)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase `readonly_pure_selector`:\n\t\t\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\t\t\t\tevictDownstreamFromSelector(target, key)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t// held selectors, by definitions, don't become promises\n\t\t\t\t\t}\n\t\t\t\t\tcloseOperation(target)\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\n/**\n * @param target - the newest layer of the store\n * @param state - the state to read from cache\n * @param mut - whether the value is intended to be mutable\n * @returns the state's current value\n */\nexport function readFromCache<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tmut: `mut` | undefined,\n): T {\n\ttarget.logger.info(`📖`, state.type, state.key, `reading cached value`)\n\tlet value = target.valueMap.get(state.key) as T\n\n\tconst mayNeedToBeCopied =\n\t\tmut === `mut` && state.type === `mutable_atom` && isChildStore(target)\n\tif (mayNeedToBeCopied) {\n\t\tconst mutableAtom = state\n\t\tconst { parent } = target\n\n\t\tif (target.valueMap.hasOwn(mutableAtom.key)) {\n\t\t\treturn value\n\t\t}\n\n\t\tconst parentValue = parent.valueMap.get(mutableAtom.key) as T &\n\t\t\tTransceiver<any, any, any>\n\n\t\ttarget.logger.info(`📃`, `atom`, mutableAtom.key, `copying`)\n\t\tconst jsonValue = parentValue.toJSON()\n\t\tconst copiedValue = mutableAtom.class.fromJSON(jsonValue)\n\t\ttarget.valueMap.set(mutableAtom.key, copiedValue)\n\t\tnew Tracker(mutableAtom, parent)\n\t\tvalue = copiedValue\n\t}\n\treturn value\n}\n\nexport function 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.getFrom(target)\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 { ViewOf } from \"atom.io\"\n\nimport type { ReadableState } from \"..\"\nimport { readFromCache, writeToCache } from \"../caching\"\nimport type { Store } from \"../store\"\n\nexport function readOrComputeValue<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tmut?: undefined,\n): ViewOf<T>\nexport function readOrComputeValue<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tmut: `mut`,\n): T\nexport function readOrComputeValue<T>(\n\ttarget: Store,\n\tstate: ReadableState<T>,\n\tmut: `mut` | undefined,\n): T {\n\tif (target.valueMap.has(state.key)) {\n\t\treturn readFromCache(target, state, mut)\n\t}\n\tconst { key } = state\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, key, `computing value`)\n\t\t\treturn state.getFrom(target)\n\t\tcase `atom`: {\n\t\t\tlet def: T\n\t\t\tif (state.default instanceof Function) {\n\t\t\t\tdef = state.default()\n\t\t\t} else {\n\t\t\t\tdef = state.default\n\t\t\t}\n\t\t\tconst cachedValue = writeToCache(target, state, def)\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\tdef,\n\t\t\t)\n\t\t\treturn cachedValue\n\t\t}\n\t\tcase `mutable_atom`: {\n\t\t\tconst instance = new state.class()\n\t\t\tconst cachedValue = writeToCache(target, state, instance)\n\t\t\ttarget.logger.info(\n\t\t\t\t`💁`,\n\t\t\t\t`mutable_atom`,\n\t\t\t\tstate.key,\n\t\t\t\t`could not find cached value; using default`,\n\t\t\t\tinstance,\n\t\t\t)\n\t\t\treturn cachedValue\n\t\t}\n\t}\n}\n","import type {\n\tMutableAtomToken,\n\tReadableToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type {\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadonlyPureSelectorFamily,\n\tRegularAtomFamily,\n\tWritableFamily,\n\tWritablePureSelectorFamily,\n} from \"..\"\nimport type { Transceiver } from \"../mutable\"\nimport { type Store, withdraw } from \"../store\"\n\nexport function getFamilyOfToken<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(store: Store, token: MutableAtomToken<T, K>): MutableAtomFamily<T, K>\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, K>,\n): RegularAtomFamily<T, K>\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, K>,\n): WritablePureSelectorFamily<T, K>\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, K>,\n): ReadonlyPureSelectorFamily<T, K>\n\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableToken<T, K>,\n): WritableFamily<T, K>\nexport function getFamilyOfToken<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K>,\n): ReadableFamily<T, K>\n\nexport function getFamilyOfToken(\n\tstore: Store,\n\ttoken: ReadableToken<any, any>,\n): ReadableFamily<any, any> {\n\treturn withdraw(store, {\n\t\t// biome-ignore lint/style/noNonNullAssertion: family is required\n\t\tkey: token.family!.key,\n\t\ttype: `${token.type}_family`,\n\t})\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.token.key,\n\t\t`Aborting transaction`,\n\t)\n\ttarget.parent.child = null\n}\n","import { type AtomIOToken, PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport { stringifyJson } from \"atom.io/json\"\n\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`${PRETTY_TOKEN_TYPES[token.type]} ${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 { Fn } from \"../utility-types\"\n\nexport function actUponStore<F extends Fn>(\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","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 {\n\tAtomToken,\n\tAtomUpdateEvent,\n\tStateUpdate,\n\tWritableToken,\n} from \"atom.io\"\n\nimport type { MutableAtom, WritableState } from \"..\"\nimport { hasRole } from \"../atom\"\nimport { readOrComputeValue } from \"../get-state\"\nimport type { Transceiver } from \"../mutable\"\nimport { isTransceiver } from \"../mutable\"\nimport type { OpenOperation } from \"../operation\"\nimport { deposit, type Store } from \"../store\"\nimport { isChildStore, isRootStore } from \"../transaction\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\n\nexport function dispatchOrDeferStateUpdate<T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tstate: WritableState<T>,\n\t[oldValue, newValue]: [T, T],\n\t_stateIsNewlyCreated: boolean,\n): void {\n\tconst { key, subject, type } = state\n\n\tconst update: StateUpdate<T> = {\n\t\toldValue: isTransceiver(oldValue) ? oldValue.READONLY_VIEW : oldValue,\n\t\tnewValue: isTransceiver(newValue) ? newValue.READONLY_VIEW : newValue,\n\t}\n\n\tif (isRootStore(target)) {\n\t\tswitch (type) {\n\t\t\tcase `mutable_atom`:\n\t\t\t\ttarget.logger.info(\n\t\t\t\t\t`📢`,\n\t\t\t\t\ttype,\n\t\t\t\t\tkey,\n\t\t\t\t\t`is now (`,\n\t\t\t\t\tnewValue,\n\t\t\t\t\t`) subscribers:`,\n\t\t\t\t\tsubject.subscribers,\n\t\t\t\t)\n\t\t\t\tbreak\n\t\t\tcase `atom`:\n\t\t\tcase `writable_pure_selector`:\n\t\t\tcase `writable_held_selector`:\n\t\t\t\ttarget.logger.info(\n\t\t\t\t\t`📢`,\n\t\t\t\t\ttype,\n\t\t\t\t\tkey,\n\t\t\t\t\t`went (`,\n\t\t\t\t\toldValue,\n\t\t\t\t\t`->`,\n\t\t\t\t\tnewValue,\n\t\t\t\t\t`) subscribers:`,\n\t\t\t\t\tsubject.subscribers,\n\t\t\t\t)\n\t\t}\n\t\tsubject.next(update)\n\t}\n\n\tif (isChildStore(target) && (type === `mutable_atom` || type === `atom`)) {\n\t\tif (target.on.transactionApplying.state === null) {\n\t\t\tconst token: WritableToken<T> = deposit(state)\n\n\t\t\tif (isTransceiver(newValue)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst { timestamp } = target.operation\n\t\t\tconst atomUpdate: AtomUpdateEvent<AtomToken<T>> = {\n\t\t\t\ttype: `atom_update`,\n\t\t\t\ttoken,\n\t\t\t\ttimestamp,\n\t\t\t\tupdate,\n\t\t\t}\n\t\t\ttarget.transactionMeta.update.subEvents.push(atomUpdate)\n\t\t\ttarget.logger.info(\n\t\t\t\t`📁`,\n\t\t\t\t`atom`,\n\t\t\t\tkey,\n\t\t\t\t`stowed (`,\n\t\t\t\toldValue,\n\t\t\t\t`->`,\n\t\t\t\tnewValue,\n\t\t\t\t`)`,\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tif (hasRole(state, `tracker:signal`)) {\n\t\t\tconst keyOfMutable = key.slice(1)\n\t\t\tconst mutable = target.atoms.get(keyOfMutable) as MutableAtom<\n\t\t\t\tTransceiver<unknown, any, any>\n\t\t\t>\n\t\t\tconst transceiver = readOrComputeValue(target, mutable, `mut`)\n\t\t\tconst accepted = transceiver.do(update.newValue) === null\n\t\t\tif (accepted === true) {\n\t\t\t\tevictDownstreamFromAtom(target, mutable)\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { Atom, OpenOperation, Store } from \"..\"\nimport { writeToCache } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport { markDone } from \"../operation\"\nimport { become } from \"./become\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\n\nexport const setAtom = <T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tatom: Atom<T>,\n\tnext: T | ((oldValue: T) => T),\n): [oldValue: T, newValue: T] => {\n\tconst oldValue = readOrComputeValue(target, atom, `mut`)\n\tlet newValue = become(next)(oldValue)\n\ttarget.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)\n\tnewValue = writeToCache(target, atom, newValue)\n\tmarkDone(target, atom.key)\n\tevictDownstreamFromAtom(target, atom)\n\treturn [oldValue, newValue]\n}\n","import type { Atom, OpenOperation, Store, WritableState } from \"..\"\nimport { traceRootSelectorAtoms } from \"..\"\nimport { dispatchOrDeferStateUpdate } from \"./dispatch-state-update\"\nimport { setAtom } from \"./set-atom\"\n\nfunction resetAtom<T>(\n\ttarget: Store & { operation: OpenOperation },\n\tatom: Atom<T>,\n): [oldValue: T, newValue: T] {\n\tswitch (atom.type) {\n\t\tcase `mutable_atom`:\n\t\t\treturn setAtom(target, atom, new atom.class())\n\t\tcase `atom`: {\n\t\t\tlet def = atom.default\n\t\t\tif (def instanceof Function) {\n\t\t\t\tdef = def()\n\t\t\t}\n\t\t\treturn setAtom(target, atom, def)\n\t\t}\n\t}\n}\n\nexport function resetAtomOrSelector<T>(\n\ttarget: Store & { operation: OpenOperation },\n\tstate: WritableState<T>,\n): [oldValue: T, newValue: T] {\n\tlet protoUpdate: [T, T]\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tprotoUpdate = resetAtom(target, 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 oldValue = state.getFrom(target)\n\t\t\t\tconst atoms = traceRootSelectorAtoms(target, state.key)\n\t\t\t\tfor (const atom of atoms.values()) {\n\t\t\t\t\tconst rootProtoUpdate = resetAtom(target, atom)\n\t\t\t\t\tdispatchOrDeferStateUpdate(target, state, rootProtoUpdate, false)\n\t\t\t\t}\n\t\t\t\tconst newValue = state.getFrom(target)\n\t\t\t\tprotoUpdate = [oldValue, newValue]\n\t\t\t}\n\t\t\tbreak\n\t}\n\n\treturn protoUpdate\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { operateOnStore, OWN_OP } from \"./operate-on-store\"\nimport type { RESET_STATE } from \"./reset-in-store\"\n\nexport function setIntoStore<T, New extends T>(\n\tstore: Store,\n\ttoken: WritableToken<T>,\n\tvalue: New | typeof RESET_STATE | ((oldValue: T) => New),\n): void\n\nexport function setIntoStore<\n\tT,\n\tK extends Canonical,\n\tNew extends T,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n\tvalue: New | typeof RESET_STATE | ((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 | typeof RESET_STATE | ((oldValue: T) => New),\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T>,\n\t\t\t\tvalue: New | typeof RESET_STATE | ((oldValue: T) => New),\n\t\t ]\n): void {\n\toperateOnStore(store, OWN_OP, ...params)\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { setIntoStore } from \"./set-into-store\"\n\nexport const RESET_STATE: unique symbol = Symbol(`RESET`)\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\tsetIntoStore(store, token, RESET_STATE)\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\tsetIntoStore(store, family, key, RESET_STATE)\n\t}\n}\n","import type { WritableSelector } from \"..\"\nimport { writeToCache } from \"../caching\"\nimport { markDone, type OpenOperation } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\n\nexport function setSelector<T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tselector: WritableSelector<T>,\n\tnext: T | ((oldValue: T) => T),\n): [oldValue: T, newValue: T] {\n\tlet oldValue: T\n\tlet newValue: T\n\tlet constant: T\n\n\tconst { type, key } = selector\n\n\tswitch (selector.type) {\n\t\tcase `writable_pure_selector`:\n\t\t\toldValue = selector.getFrom(target)\n\t\t\tnewValue = become(next)(oldValue)\n\t\t\twriteToCache(target, selector, newValue)\n\t\t\tbreak\n\t\tcase `writable_held_selector`:\n\t\t\tconstant = selector.const\n\t\t\tbecome(next)(constant)\n\t\t\toldValue = constant\n\t\t\tnewValue = constant\n\t}\n\n\ttarget.logger.info(`📝`, type, key, `setting to`, newValue)\n\tmarkDone(target, key)\n\tselector.setSelf(newValue)\n\treturn [oldValue, newValue]\n}\n","import type { WritableState } from \"..\"\nimport type { OpenOperation } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { setAtom } from \"./set-atom\"\nimport { setSelector } from \"./set-selector\"\n\nexport const setAtomOrSelector = <T>(\n\ttarget: Store & { operation: OpenOperation },\n\tstate: WritableState<T>,\n\tvalue: T | ((oldValue: T) => T),\n): [oldValue: T, newValue: T] => {\n\tlet protoUpdate: [T, T]\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tprotoUpdate = setAtom(target, state, value)\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\tprotoUpdate = setSelector(target, state, value)\n\t\t\tbreak\n\t}\n\n\treturn protoUpdate\n}\n","import type { AtomUpdateEvent } from \"atom.io\"\n\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\n\nexport function ingestAtomUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tatomUpdate: AtomUpdateEvent<any>,\n\tstore: Store,\n): void {\n\tconst {\n\t\ttoken,\n\t\tupdate: { newValue, oldValue },\n\t} = atomUpdate\n\tconst value = applying === `newValue` ? newValue : oldValue\n\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\tMoleculeCreationEvent,\n\tMoleculeDisposalEvent,\n\tMoleculeTransferEvent,\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: MoleculeCreationEvent = {\n\t\ttype: `molecule_creation`,\n\t\tkey,\n\t\tprovenance: origin,\n\t\ttimestamp: Date.now(),\n\t}\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.subEvents.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`key`,\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`key`,\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: MoleculeDisposalEvent = {\n\t\ttype: `molecule_disposal`,\n\t\tkey: molecule.key,\n\t\tvalues,\n\t\tprovenance,\n\t\ttimestamp: Date.now(),\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.subEvents.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`key`,\n\t\t\tstringKey,\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`key`,\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: MoleculeTransferEvent = {\n\t\ttype: `molecule_transfer`,\n\t\tkey: molecule.key,\n\t\texclusive: Boolean(exclusive),\n\t\tfrom: priorProvenance,\n\t\tto: [newProvenanceMolecule.key],\n\t\ttimestamp: Date.now(),\n\t}\n\tconst isTransaction =\n\t\tisChildStore(target) && target.transactionMeta.phase === `building`\n\tif (isTransaction) {\n\t\ttarget.transactionMeta.update.subEvents.push(transferEvent)\n\t}\n\n\treturn claim\n}\n","import type {\n\tMoleculeCreationEvent,\n\tMoleculeDisposalEvent,\n\tMoleculeTransferEvent,\n\tReadableToken,\n\tStateCreationEvent,\n\tStateDisposalEvent,\n} from \"atom.io\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\n\nimport { disposeFromStore } from \"../families\"\nimport { mintInStore, MUST_CREATE } from \"../families/mint-in-store\"\nimport {\n\tallocateIntoStore,\n\tclaimWithinStore,\n\tdeallocateFromStore,\n} from \"../molecule\"\nimport type { Store } from \"../store\"\n\nexport function ingestCreationEvent(\n\tupdate: StateCreationEvent<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: StateDisposalEvent<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: StateCreationEvent<any> | StateDisposalEvent<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\tmintInStore(store, family, parseJson(familyMeta.subKey), MUST_CREATE)\n\t\t}\n\t}\n}\n\nexport function ingestMoleculeCreationEvent(\n\tupdate: MoleculeCreationEvent,\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: MoleculeDisposalEvent,\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\tmintInStore(store, family, update.key, MUST_CREATE)\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: MoleculeTransferEvent,\n\tapplying: `newValue` | `oldValue`,\n\tstore: Store,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\t{\n\t\t\t\tfor (const newOwner of update.to) {\n\t\t\t\t\tclaimWithinStore<any, any, any>(\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tnewOwner,\n\t\t\t\t\t\tupdate.key,\n\t\t\t\t\t\tupdate.exclusive ? `exclusive` : undefined,\n\t\t\t\t\t)\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\tlet exclusivity: `exclusive` | undefined = `exclusive`\n\t\t\t\tfor (const previousOwner of update.from) {\n\t\t\t\t\tclaimWithinStore<any, any, any>(\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tpreviousOwner,\n\t\t\t\t\t\tupdate.key,\n\t\t\t\t\t\texclusivity,\n\t\t\t\t\t)\n\t\t\t\t\texclusivity = undefined\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t}\n}\n","import type {\n\tAtomOnly,\n\tAtomUpdateEvent,\n\tTimelineManageable,\n\tTimelineSelectorUpdateEvent,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\n\nexport function ingestSelectorUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tselectorUpdate: TimelineSelectorUpdateEvent<any>,\n\tstore: Store,\n): void {\n\tlet updates: AtomUpdateEvent<AtomOnly<TimelineManageable>>[]\n\tif (applying === `newValue`) {\n\t\tupdates = selectorUpdate.atomUpdates\n\t} else {\n\t\tupdates = selectorUpdate.atomUpdates.toReversed()\n\t}\n\tfor (const atomUpdate of updates) {\n\t\tingestAtomUpdate(applying, atomUpdate, store)\n\t}\n}\n","import type { TransactionOutcomeEvent } 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: TransactionOutcomeEvent<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? transactionUpdate.subEvents\n\t\t\t: [...transactionUpdate.subEvents].reverse()\n\tfor (const updateFromTransaction of updates) {\n\t\tswitch (updateFromTransaction.type) {\n\t\t\tcase `atom_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_outcome`:\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 { Fn } from \"../utility-types\"\nimport { isChildStore, isRootStore } from \"./is-root-store\"\nimport { setEpochNumberOfAction } from \"./set-epoch-number\"\n\nexport const applyTransaction = <F extends Fn>(\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 { subEvents: updates } = child.transactionMeta.update\n\tstore.logger.info(\n\t\t`🛄`,\n\t\t`transaction`,\n\t\tchild.transactionMeta.update.token.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.token.key,\n\t\t\tchild.transactionMeta.update.epoch,\n\t\t)\n\t\tconst myTransaction = withdraw<Fn>(store, {\n\t\t\tkey: child.transactionMeta.update.token.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.token.key,\n\t\t\t`Finished applying transaction.`,\n\t\t)\n\t} else if (isChildStore(parent)) {\n\t\tparent.transactionMeta.update.subEvents.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\tTransactionToken,\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 { Fn } 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\ttoken: TransactionToken<any>,\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, token.key)\n\tconst transactionMeta: TransactionProgress<Fn> = {\n\t\tphase: `building`,\n\t\tupdate: {\n\t\t\ttype: `transaction_outcome`,\n\t\t\ttoken,\n\t\t\tid,\n\t\t\tepoch: epoch === undefined ? Number.NaN : epoch + 1,\n\t\t\ttimestamp: Date.now(),\n\t\t\tsubEvents: [],\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: (t, identifier = arbitrary()) => actUponStore(child, t, identifier),\n\t\t\tfind: ((...ps: Parameters<typeof findState>) =>\n\t\t\t\tfindInStore(store, ...ps)) as typeof findState,\n\t\t\tjson: (t) => getJsonToken(child, t),\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\ttoken.key,\n\t\t`Building transaction with params:`,\n\t\tparams,\n\t)\n\treturn child\n}\n","import type {\n\tTransactionOptions,\n\tTransactionOutcomeEvent,\n\tTransactionToken,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { Fn } from \"../utility-types\"\nimport { abortTransaction } from \"./abort-transaction\"\nimport { applyTransaction } from \"./apply-transaction\"\nimport { buildTransaction } from \"./build-transaction\"\n\nexport type Transaction<F extends Fn> = {\n\tkey: string\n\ttype: `transaction`\n\tinstall: (store: Store) => void\n\tsubject: Subject<TransactionOutcomeEvent<TransactionToken<F>>>\n\trun: (parameters: Parameters<F>, id?: string) => ReturnType<F>\n}\n\nexport function createTransaction<F extends Fn>(\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 token = deposit(newTransaction)\n\t\t\tconst childStore = buildTransaction(store, token, 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 {\n\tActorToolkit,\n\tTransactionOutcomeEvent,\n\tTransactionToken,\n} from \"atom.io\"\n\nimport type { Junction } from \"../junction\"\nimport type { Fn } 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 Fn> = {\n\tphase: `applying` | `building`\n\tupdate: TransactionOutcomeEvent<TransactionToken<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\tReadableFamilyToken,\n\tReadableToken,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\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: Canonical,\n): ReadableToken<any> {\n\tconst family = withdraw(store, token)\n\tconst state = family(key)\n\n\treturn state\n}\n","import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { COUNTERFEIT, mint } from \"../store\"\nimport { isChildStore, isRootStore } from \"../transaction\"\nimport { initFamilyMemberInStore } from \"./init-family-member\"\n\nexport const MUST_CREATE: unique symbol = Symbol(`MUST_NOT_EXIST`)\n\nexport function mintInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\tfamilyToken: WritableFamilyToken<T, K>,\n\tkey: Key,\n\tinit?: typeof MUST_CREATE,\n): WritableToken<T, K>\nexport function mintInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n\tinit?: typeof MUST_CREATE,\n): ReadableToken<T, K>\nexport function mintInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n\tshouldCreate?: typeof MUST_CREATE,\n): ReadableToken<T, K> {\n\tlet stateToken: ReadableToken<T, K>\n\n\tlet willCreate: boolean\n\tswitch (shouldCreate) {\n\t\tcase MUST_CREATE:\n\t\t\twillCreate = true\n\t\t\tbreak\n\t\tcase undefined:\n\t\t\twillCreate = false\n\t\t\tbreak\n\t}\n\n\tconst stringKey = stringifyJson(key)\n\tconst molecule = store.molecules.get(stringKey)\n\tif (!molecule && store.config.lifespan === `immortal`) {\n\t\tconst fakeToken = mint(familyToken, key, COUNTERFEIT)\n\t\tstore.logger.warn(\n\t\t\t`💣`,\n\t\t\t`key`,\n\t\t\tstringKey,\n\t\t\t`was used to mint a counterfeit token for`,\n\t\t\tfamilyToken.type,\n\t\t\t`\"${familyToken.key}\"`,\n\t\t)\n\t\treturn fakeToken\n\t}\n\n\tif (willCreate) {\n\t\tstateToken = initFamilyMemberInStore(store, familyToken, key)\n\t\tconst target = newest(store)\n\t\tif (stateToken.family) {\n\t\t\tif (isRootStore(target)) {\n\t\t\t\tswitch (stateToken.type) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\tstore.on.atomCreation.next(stateToken)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\t\tcase `readonly_pure_selector`:\n\t\t\t\t\tcase `writable_held_selector`:\n\t\t\t\t\tcase `readonly_held_selector`:\n\t\t\t\t\t\tstore.on.selectorCreation.next(stateToken)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisChildStore(target) &&\n\t\t\t\ttarget.on.transactionApplying.state === null\n\t\t\t) {\n\t\t\t\ttarget.transactionMeta.update.subEvents.push({\n\t\t\t\t\ttype: `state_creation`,\n\t\t\t\t\ttoken: stateToken,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\tif (molecule) {\n\t\t\ttarget.moleculeData.set(stringKey, familyToken.key)\n\t\t}\n\t} else {\n\t\tstateToken = mint(familyToken, key)\n\t}\n\treturn stateToken\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { type Canonical, parseJson } from \"atom.io/json\"\n\nimport { seekInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { mintInStore, MUST_CREATE } from \"../families/mint-in-store\"\nimport type { OpenOperation } from \"../operation\"\nimport { closeOperation, openOperation } from \"../operation\"\nimport { type Store, withdraw } from \"../store\"\nimport { dispatchOrDeferStateUpdate } from \"./dispatch-state-update\"\nimport { resetAtomOrSelector } from \"./reset-atom-or-selector\"\nimport { RESET_STATE } from \"./reset-in-store\"\nimport { setAtomOrSelector } from \"./set-atom-or-selector\"\n\nexport const OWN_OP: unique symbol = Symbol(`OWN_OP`)\nexport const JOIN_OP: unique symbol = Symbol(`JOIN_OP`)\n\nexport function operateOnStore<T, New extends T>(\n\tstore: Store,\n\topMode: typeof JOIN_OP | typeof OWN_OP,\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 | typeof RESET_STATE | ((oldValue: T) => New),\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T>,\n\t\t\t\tvalue: New | typeof RESET_STATE | ((oldValue: T) => New),\n\t\t ]\n): void {\n\tlet existingToken: WritableToken<T> | undefined\n\tlet brandNewToken: WritableToken<T> | undefined\n\tlet token: WritableToken<T>\n\tlet family: WritableFamilyToken<T, Canonical> | null\n\tlet key: Canonical | null\n\tlet value: New | typeof RESET_STATE | ((oldValue: T) => New)\n\tif (params.length === 2) {\n\t\ttoken = params[0]\n\t\tvalue = params[1]\n\t\tif (`family` in token) {\n\t\t\tfamily = getFamilyOfToken(store, token)\n\t\t\tkey = parseJson(token.family.subKey)\n\t\t\texistingToken = seekInStore(store, family, key)\n\t\t\tif (!existingToken) {\n\t\t\t\tbrandNewToken = mintInStore(store, family, key, MUST_CREATE)\n\t\t\t\ttoken = brandNewToken\n\t\t\t} else {\n\t\t\t\ttoken = existingToken\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfamily = params[0]\n\t\tkey = params[1]\n\t\tvalue = params[2]\n\t\texistingToken = seekInStore(store, family, key)\n\t\tif (!existingToken) {\n\t\t\tbrandNewToken = mintInStore(store, family, key, MUST_CREATE)\n\t\t\ttoken = brandNewToken\n\t\t} else {\n\t\t\ttoken = existingToken\n\t\t}\n\t}\n\n\tconst action = value === RESET_STATE ? `reset` : `set`\n\n\tlet target: Store & { operation: OpenOperation }\n\n\tif (opMode === OWN_OP) {\n\t\tconst result = openOperation(store, token)\n\t\tconst rejected = typeof result === `number`\n\t\tif (rejected) {\n\t\t\tconst rejectionTime = result\n\t\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t\t`waiting to ${action} \"${token.key}\" at T-${rejectionTime}`,\n\t\t\t\tfunction waitUntilOperationCloseToSetState() {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`🟢`,\n\t\t\t\t\t\ttoken.type,\n\t\t\t\t\t\ttoken.key,\n\t\t\t\t\t\t`resuming deferred`,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\t`from T-${rejectionTime}`,\n\t\t\t\t\t)\n\t\t\t\t\toperateOnStore(store, opMode, token, value)\n\t\t\t\t},\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\ttarget = result\n\t} else {\n\t\ttarget = store as Store & { operation: OpenOperation }\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`,\n\t\t\taction,\n\t\t\t`because key`,\n\t\t\tsubKey,\n\t\t\t`is not allocated.`,\n\t\t\tdisposal\n\t\t\t\t? `this key was previously disposed:${disposal.trace}`\n\t\t\t\t: `(no previous disposal trace found)`,\n\t\t)\n\t\treturn\n\t}\n\n\tconst state = withdraw(target, token)\n\tlet protoUpdate: [T, T]\n\tif (value === RESET_STATE) {\n\t\tprotoUpdate = resetAtomOrSelector(target, state)\n\t} else {\n\t\tprotoUpdate = setAtomOrSelector(target, state, value)\n\t}\n\tconst isNewlyCreated = Boolean(brandNewToken)\n\tdispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated)\n\n\tif (opMode === OWN_OP) {\n\t\tcloseOperation(target)\n\t}\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 function getSelectorDependencyKeys(\n\tstore: Store,\n\tkey: string,\n): (AtomKey<unknown> | ReadonlySelectorKey<unknown> | SelectorKey<unknown>)[] {\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 function 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 { ReadableToken } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { traceRootSelectorAtoms } from \"./trace-selector-atoms\"\n\nexport function 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: ReadableToken<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 { Canonical } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { getFallback } from \"../get-state/get-fallback\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport { reduceReference } from \"../get-state/reduce-reference\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { JOIN_OP, operateOnStore } from \"../set-state/operate-on-store\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { updateSelectorAtoms } from \"./update-selector-atoms\"\n\nexport function 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\treturn {\n\t\tget: (\n\t\t\t...params:\n\t\t\t\t| [ReadableFamilyToken<any, any>, Canonical]\n\t\t\t\t| [ReadableToken<any>]\n\t\t) => {\n\t\t\tconst target = newest(store)\n\t\t\tconst { token, familyToken, subKey } = reduceReference(store, ...params)\n\t\t\tlet dependencyValue: unknown\n\t\t\tif (`counterfeit` in token && familyToken && subKey) {\n\t\t\t\tconst dependencyFamily = withdraw(store, familyToken)\n\t\t\t\tdependencyValue = getFallback(store, token, dependencyFamily, subKey)\n\t\t\t} else {\n\t\t\t\tconst dependency = withdraw(store, token)\n\t\t\t\tdependencyValue = readOrComputeValue(store, dependency)\n\t\t\t}\n\n\t\t\tstore.logger.info(\n\t\t\t\t`🔌`,\n\t\t\t\tselectorType,\n\t\t\t\tselectorKey,\n\t\t\t\t`registers dependency ( \"${token.key}\" =`,\n\t\t\t\tdependencyValue,\n\t\t\t\t`)`,\n\t\t\t)\n\n\t\t\ttarget.selectorGraph.set(\n\t\t\t\t{\n\t\t\t\t\tupstreamSelectorKey: token.key,\n\t\t\t\t\tdownstreamSelectorKey: selectorKey,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tsource: token.key,\n\t\t\t\t},\n\t\t\t)\n\t\t\tupdateSelectorAtoms(store, selectorType, selectorKey, token, covered)\n\t\t\treturn dependencyValue\n\t\t},\n\t\tset: (<T, K extends Canonical, New extends T, Key extends K>(\n\t\t\t...params:\n\t\t\t\t| [\n\t\t\t\t\t\ttoken: WritableFamilyToken<T, K>,\n\t\t\t\t\t\tkey: Key,\n\t\t\t\t\t\tvalue: New | ((oldValue: any) => New),\n\t\t\t\t ]\n\t\t\t\t| [token: WritableToken<T>, value: New | ((oldValue: T) => New)]\n\t\t) => {\n\t\t\tconst target = newest(store)\n\t\t\toperateOnStore(target, JOIN_OP, ...params)\n\t\t}) as typeof setState,\n\t\tfind: ((...args: Parameters<typeof findState>) =>\n\t\t\tfindInStore(store, ...args)) as typeof findState,\n\t\tjson: (token) => getJsonToken(store, token),\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyHeldSelectorOptions,\n\tReadonlyHeldSelectorToken,\n} from \"atom.io\"\n\nimport type { ReadonlyHeldSelector } from \"..\"\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function 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\n\tconst getFrom = (innerTarget: 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\twriteToCache(innerTarget, readonlySelector, constant)\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\tgetFrom,\n\t\tinstall: (s: Store) => createReadonlyHeldSelector(s, options, family),\n\t}\n\tif (family) {\n\t\treadonlySelector.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 { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function 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\n\tconst getFrom = () => {\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 = writeToCache(innerTarget, readonlySelector, value)\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\tgetFrom,\n\t\tinstall: (s: Store) => createReadonlyPureSelector(s, options, family),\n\t}\n\tif (family) {\n\t\treadonlySelector.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 type {\n\tFamilyMetadata,\n\tWritableHeldSelectorOptions,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\n\nimport type { WritableHeldSelector } from \"..\"\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function 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 getFrom = (innerTarget: 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\toptions.get(getterToolkit, constant)\n\t\twriteToCache(innerTarget, mySelector, constant)\n\t\tstore.logger.info(`✨`, type, key, `=`, constant)\n\t\tcovered.clear()\n\t\treturn constant\n\t}\n\n\tconst setSelf = (): void => {\n\t\toptions.set(setterToolkit, constant)\n\t}\n\n\tconst mySelector: WritableHeldSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tgetFrom,\n\t\tsetSelf,\n\t\tinstall: (s: Store) => createWritableHeldSelector(s, options, family),\n\t}\n\tif (family) {\n\t\tmySelector.family = family\n\t}\n\ttarget.writableSelectors.set(key, mySelector)\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 { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function 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 getFrom = (innerTarget: 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 = options.get(getterToolkit)\n\t\tconst cached = writeToCache(innerTarget, mySelector, value)\n\t\tstore.logger.info(`✨`, type, key, `=`, cached)\n\t\tcovered.clear()\n\t\treturn cached\n\t}\n\n\tconst setSelf = (newValue: T): void => {\n\t\toptions.set(setterToolkit, newValue)\n\t}\n\n\tconst mySelector: WritablePureSelector<T> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tgetFrom,\n\t\tsetSelf,\n\t\tinstall: (s: Store) => createWritablePureSelector(s, options, family),\n\t}\n\tif (family) mySelector.family = family\n\n\ttarget.writableSelectors.set(key, mySelector)\n\tconst initialValue = getFrom(target)\n\tstore.logger.info(`✨`, mySelector.type, mySelector.key, `=`, initialValue)\n\n\tconst token: WritablePureSelectorToken<T> = { key, type }\n\tif (family) token.family = family\n\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, family: familyMeta } = selectorToken\n\tif (!familyMeta) {\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(familyMeta.subKey)\n\t\tif (molecule) {\n\t\t\ttarget.moleculeData.delete(familyMeta.subKey, familyMeta.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: familyMeta.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\ttimestamp: Date.now(),\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: familyMeta.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\ttimestamp: Date.now(),\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: familyMeta.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\ttimestamp: Date.now(),\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: familyMeta.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\ttimestamp: Date.now(),\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\ttarget.moleculeData.delete(familyMeta.key, familyMeta.subKey)\n\t\tstore.logger.info(`🔥`, selectorToken.type, key, `deleted`)\n\t\tif (isChildStore(target) && target.transactionMeta.phase === `building`) {\n\t\t\ttarget.transactionMeta.update.subEvents.push({\n\t\t\t\ttype: `state_disposal`,\n\t\t\t\tsubType: `selector`,\n\t\t\t\ttoken: selectorToken,\n\t\t\t\ttimestamp: Date.now(),\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\tStateLifecycleEvent,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } 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\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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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\tStateLifecycleEvent<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, timestamp: Date.now() })\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\tStateLifecycleEvent,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport 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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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<StateLifecycleEvent<RegularAtomToken<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, timestamp: Date.now() })\n\t\treturn token\n\t}\n\n\tconst atomFamily = Object.assign(familyFunction, familyToken, {\n\t\tdefault: options.default,\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\tif (options.default instanceof Function === false) {\n\t\tstore.defaults.set(options.key, options.default)\n\t}\n\treturn familyToken\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyHeldSelectorFamilyOptions,\n\tReadonlyHeldSelectorFamilyToken,\n\tReadonlyHeldSelectorToken,\n\tStateLifecycleEvent,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ReadonlyHeldSelectorFamily } 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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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\tStateLifecycleEvent<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, timestamp: Date.now() })\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\tStateLifecycleEvent,\n\tWritableHeldSelectorFamilyOptions,\n\tWritableHeldSelectorFamilyToken,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport 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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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\tStateLifecycleEvent<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, timestamp: Date.now() })\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\tStateLifecycleEvent,\n\tWritablePureSelectorFamilyOptions,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } 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\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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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\tStateLifecycleEvent<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, timestamp: Date.now() })\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 } 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, any, any>,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, K>,\n\tkey: Key,\n): MutableAtomToken<T, 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 } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport { type Store, withdraw } from \"../store\"\nimport { mintInStore } from \"./mint-in-store\"\nimport { seekInStore } from \"./seek-in-store\"\n\n// seek [token 🟧] [inits ⬛]\n// find [token ✅] [inits ⬛]\n// mint [token ✅] [inits 🟧]\n// init [token ✅] [inits ✅]\n\nexport function findInStore<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\tfamilyToken: MutableAtomFamilyToken<T, K>,\n\tkey: Key,\n): MutableAtomToken<T, K>\n\nexport function findInStore<T, K extends Canonical, Key extends K>(\n\tstore: Store,\n\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: 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\tfamilyToken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T, K>\n\nexport function findInStore(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<any, any>,\n\tkey: Canonical,\n): ReadableToken<any> {\n\twithdraw(store, familyToken)\n\tconst existingStateToken = seekInStore(store, familyToken, key)\n\tif (existingStateToken) {\n\t\treturn existingStateToken\n\t}\n\tconst newStateToken = mintInStore(store, familyToken, key)\n\treturn newStateToken\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, parseJson } from \"atom.io/json\"\n\nimport { seekInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { mintInStore, MUST_CREATE } from \"../families/mint-in-store\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\n\nexport function reduceReference<T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K>, key: K]\n\t\t| [token: ReadableToken<T>]\n): {\n\ttoken: ReadableToken<T>\n\tfamilyToken: ReadableFamilyToken<T, K> | undefined\n\tsubKey: K | undefined\n\tisNew: boolean\n} {\n\tlet existingToken: ReadableToken<T> | undefined\n\tlet brandNewToken: ReadableToken<T> | undefined\n\tlet familyToken: ReadableFamilyToken<T, K> | undefined\n\tlet subKey: K | undefined\n\tlet token: ReadableToken<T, K>\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t\tif (`family` in token) {\n\t\t\tfamilyToken = getFamilyOfToken(store, token)\n\t\t\twithdraw(store, familyToken)\n\t\t\tsubKey = parseJson(token.family.subKey)\n\t\t\texistingToken = seekInStore(store, familyToken, subKey)\n\t\t\tif (`counterfeit` in token) {\n\t\t\t\treturn {\n\t\t\t\t\ttoken,\n\t\t\t\t\tfamilyToken,\n\t\t\t\t\tsubKey,\n\t\t\t\t\tisNew: false,\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!existingToken) {\n\t\t\t\tbrandNewToken = mintInStore(store, familyToken, subKey, MUST_CREATE)\n\t\t\t\ttoken = brandNewToken\n\t\t\t} else {\n\t\t\t\ttoken = existingToken\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfamilyToken = params[0]\n\t\tsubKey = params[1]\n\t\texistingToken = seekInStore(store, familyToken, subKey)\n\t\tif (!existingToken) {\n\t\t\tbrandNewToken = mintInStore(store, familyToken, subKey, MUST_CREATE)\n\t\t\ttoken = brandNewToken\n\t\t} else {\n\t\t\ttoken = existingToken\n\t\t}\n\t}\n\n\treturn {\n\t\ttoken,\n\t\tfamilyToken,\n\t\tsubKey,\n\t\tisNew: Boolean(brandNewToken),\n\t}\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { type Store, withdraw } from \"../store\"\nimport { getFallback } from \"./get-fallback\"\nimport { readOrComputeValue } from \"./read-or-compute-value\"\nimport { reduceReference } from \"./reduce-reference\"\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\tconst { token, familyToken, subKey } = reduceReference(store, ...params)\n\n\tif (`counterfeit` in token && familyToken && subKey) {\n\t\tconst family = withdraw(store, familyToken)\n\t\treturn getFallback(store, token, family, subKey)\n\t}\n\tconst state = withdraw(store, token)\n\n\treturn readOrComputeValue(store, state)\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 { ReadableToken, StateUpdate, UpdateHandler } from \"atom.io\"\n\nimport { readOrComputeValue } from \"../get-state\"\nimport { reduceReference } from \"../get-state/reduce-reference\"\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\treduceReference(store, token)\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 {\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 } from \"atom.io/json\"\n\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tFn,\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, any, any>>(\n\tstore: Store,\n\ttoken: MutableAtomToken<T, any>,\n): MutableAtom<T>\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, any, any>,\n\tK extends Canonical,\n>(store: Store, token: MutableAtomFamilyToken<T, K>): MutableAtomFamily<T, 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 Fn>(\n\tstore: Store,\n\ttoken: TransactionToken<T>,\n): Transaction<T extends Fn ? 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 { TimelineEvent, TimelineManageable, TimelineToken } from \"atom.io\"\n\nimport type { Store } from \"../store/store\"\nimport { withdraw } from \"../store/withdraw\"\n\nexport const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(\n\tstore: Store,\n\ttoken: TimelineToken<ManagedAtom>,\n\tkey: string,\n\thandleUpdate: (update: TimelineEvent<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 { Fn, Store } from \"..\"\nimport { withdraw } from \"..\"\n\nexport const subscribeToTransaction = <F extends Fn>(\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 {\n\tReadableToken,\n\tTimelineEvent,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tTransactionUpdateHandler,\n\tUpdateHandler,\n} from \"atom.io\"\n\nimport { arbitrary } from \"../arbitrary\"\nimport type { Store } from \"../store\"\nimport type { Fn } from \"../utility-types\"\nimport { subscribeToState } from \"./subscribe-to-state\"\nimport { subscribeToTimeline } from \"./subscribe-to-timeline\"\nimport { subscribeToTransaction } from \"./subscribe-to-transaction\"\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 Fn>(\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: TimelineEvent<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: TimelineEvent<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","import type { FamilyMetadata, MutableAtomToken, RegularAtomToken } from \"atom.io\"\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 { SignalFrom, 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<T extends Transceiver<any, any, any>> {\n\tprivate initializeSignalAtom(\n\t\tmutableState: MutableAtomToken<T>,\n\t\tstore: Store,\n\t): RegularAtomToken<SignalFrom<T> | null> {\n\t\tconst latestSignalStateKey = `*${mutableState.key}`\n\t\tstore.atoms.delete(latestSignalStateKey)\n\t\tstore.valueMap.delete(latestSignalStateKey)\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 latestSignalState = createRegularAtom<SignalFrom<T> | null>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: latestSignalStateKey,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\tfamilyMetaData,\n\t\t\t[`tracker:signal`],\n\t\t)\n\t\tif (store.parent?.valueMap.has(latestSignalStateKey)) {\n\t\t\tconst parentValue = store.parent.valueMap.get(latestSignalStateKey)\n\t\t\tstore.valueMap.set(latestSignalStateKey, parentValue)\n\t\t}\n\n\t\treturn latestSignalState\n\t}\n\n\tprivate unsubscribeFromInnerValue!: () => void\n\tprivate unsubscribeFromState!: () => void\n\tprivate captureSignalsFromCore(\n\t\tmutableState: MutableAtomToken<T, any>,\n\t\tlatestSignalState: RegularAtomToken<SignalFrom<T> | null>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst stateKey = mutableState.key\n\t\tconst storeName = target.config.name\n\t\tconst storeStatus = isChildStore(target)\n\t\t\t? target.transactionMeta.update.token.key\n\t\t\t: `main`\n\t\tconst subscriptionKey = `tracker:${storeName}:${storeStatus}:${stateKey}`\n\t\tconst trackerCapturesOutboundSignal = (update: SignalFrom<T>) => {\n\t\t\tsetIntoStore(target, latestSignalState, update)\n\t\t}\n\t\tconst originalInnerValue = getFromStore(target, mutableState)\n\t\tthis.unsubscribeFromInnerValue = originalInnerValue.subscribe(\n\t\t\tsubscriptionKey,\n\t\t\ttrackerCapturesOutboundSignal,\n\t\t)\n\t\tthis.unsubscribeFromState = subscribeToState(\n\t\t\ttarget,\n\t\t\tmutableState,\n\t\t\tsubscriptionKey,\n\t\t\tfunction trackerLooksForNewReference(update: SignalFrom<T>) {\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\ttrackerCapturesOutboundSignal,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}.bind(this),\n\t\t)\n\t}\n\n\tprivate supplySignalsToCore(\n\t\tmutableState: MutableAtomToken<T>,\n\t\tlatestSignalState: RegularAtomToken<SignalFrom<T> | null>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst subscriptionKey = `tracker:${target.config.name}:${\n\t\t\tisChildStore(target) ? target.transactionMeta.update.token.key : `main`\n\t\t}:${mutableState.key}`\n\t\tsubscribeToState(\n\t\t\ttarget,\n\t\t\tlatestSignalState,\n\t\t\tsubscriptionKey,\n\t\t\tfunction trackerCapturesInboundSignal({ newValue, oldValue }) {\n\t\t\t\tconst timelineId = target.timelineTopics.getRelatedKey(\n\t\t\t\t\tlatestSignalState.key,\n\t\t\t\t)\n\n\t\t\t\tif (timelineId && target.timelines.get(timelineId)?.timeTraveling) {\n\t\t\t\t\tconst unsubscribe = subscribeToTimeline(\n\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t{ key: timelineId, type: `timeline` },\n\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\tfunction trackerWaitsForTimeTravelToFinish(update) {\n\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\tsetIntoStore(target, mutableState, (transceiver) => {\n\t\t\t\t\t\t\t\tif (update === `redo` && newValue) {\n\t\t\t\t\t\t\t\t\ttransceiver.do(newValue)\n\t\t\t\t\t\t\t\t} else if (update === `undo` && oldValue) {\n\t\t\t\t\t\t\t\t\ttransceiver.undo(oldValue)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn transceiver\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\treturn\n\t\t\t\t}\n\n\t\t\t\tconst mutable = getFromStore(target, mutableState)\n\t\t\t\tconst updateNumber = mutable.getUpdateNumber(newValue)\n\t\t\t\tconst eventOffset = updateNumber - mutable.cacheUpdateNumber\n\t\t\t\tif (newValue && eventOffset === 1) {\n\t\t\t\t\tsetIntoStore(\n\t\t\t\t\t\ttarget,\n\t\t\t\t\t\tmutableState,\n\t\t\t\t\t\t(transceiver) => (transceiver.do(newValue), transceiver),\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tconst expected = mutable.cacheUpdateNumber + 1\n\t\t\t\t\ttarget.logger.info(\n\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t`mutable_atom`,\n\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t`could not be updated. Expected update number`,\n\t\t\t\t\t\texpected,\n\t\t\t\t\t\t`but got`,\n\t\t\t\t\t\tupdateNumber,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n\n\tpublic mutableAtomToken: MutableAtomToken<T>\n\tpublic latestSignalToken: RegularAtomToken<SignalFrom<T> | null>\n\n\tpublic [Symbol.dispose]!: () => void\n\n\tpublic constructor(mutableAtomToken: MutableAtomToken<T>, store: Store) {\n\t\tconst target = newest(store)\n\t\tconst latestSignalToken = this.initializeSignalAtom(mutableAtomToken, target)\n\t\tthis.mutableAtomToken = mutableAtomToken\n\t\tthis.latestSignalToken = latestSignalToken\n\t\tthis.captureSignalsFromCore(mutableAtomToken, latestSignalToken, target)\n\t\tthis.supplySignalsToCore(mutableAtomToken, latestSignalToken, target)\n\t\ttarget.trackers.set(mutableAtomToken.key, this)\n\t\tthis[Symbol.dispose] = () => {\n\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\tthis.unsubscribeFromState()\n\t\t\ttarget.trackers.delete(mutableAtomToken.key)\n\t\t}\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\n\nimport type { MutableAtom } from \"..\"\nimport { createStandaloneSelector, 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<T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\toptions: MutableAtomOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n): MutableAtomToken<T> {\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<{\n\t\tnewValue: T\n\t\toldValue: T\n\t}>()\n\tconst newAtom: MutableAtom<T> = {\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\tcreateStandaloneSelector(store, {\n\t\t\tkey: `${key}:JSON`,\n\t\t\tget: ({ get }) => get(token).toJSON(),\n\t\t\tset: ({ set }, newValue) => {\n\t\t\t\tset(token, options.class.fromJSON(newValue))\n\t\t\t},\n\t\t})\n\t}\n\tstore.on.atomCreation.next(token)\n\treturn token\n}\n","import type { MutableAtomToken, StateLifecycleEvent } from \"atom.io\"\nimport 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 { SignalFrom, Transceiver } from \"./transceiver\"\n\nexport class FamilyTracker<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n> {\n\tprivate trackers: Map<K, Tracker<T>> = new Map()\n\n\tpublic readonly latestSignalAtoms: RegularAtomFamily<SignalFrom<T> | null, K>\n\tpublic readonly mutableAtoms: MutableAtomFamily<T, K>\n\n\tpublic constructor(mutableAtoms: MutableAtomFamily<T, K>, store: Store) {\n\t\tconst latestSignalAtoms = createRegularAtomFamily<SignalFrom<T> | null, K>(\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.latestSignalAtoms = withdraw(store, latestSignalAtoms)\n\t\tthis.mutableAtoms = mutableAtoms\n\t\tconst trackerFamilyWatchesForCreationAndDisposalEvents = (\n\t\t\tevent: StateLifecycleEvent<MutableAtomToken<T>>,\n\t\t) => {\n\t\t\tconst { type, token } = event\n\t\t\tif (token.family) {\n\t\t\t\tconst key = parseJson(token.family.subKey)\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase `state_creation`:\n\t\t\t\t\t\tthis.trackers.set(key, new Tracker<T>(token, store))\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `state_disposal`: {\n\t\t\t\t\t\tconst tracker = this.trackers.get(key)\n\t\t\t\t\t\tif (tracker) {\n\t\t\t\t\t\t\ttracker[Symbol.dispose]()\n\t\t\t\t\t\t\tthis.trackers.delete(key)\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\tthis.mutableAtoms.subject.subscribe(\n\t\t\t`store=${store.config.name}::tracker-atom-family`,\n\t\t\ttrackerFamilyWatchesForCreationAndDisposalEvents,\n\t\t)\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tMutableAtomFamilyOptions,\n\tMutableAtomFamilyToken,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tStateLifecycleEvent,\n} from \"atom.io\"\nimport { PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createWritablePureSelectorFamily, type MutableAtomFamily } 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 { AsJSON, Transceiver } from \"./transceiver\"\n\nexport function createMutableAtomFamily<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\toptions: MutableAtomFamilyOptions<T, K>,\n\tinternalRoles?: string[],\n): MutableAtomFamilyToken<T, K> {\n\tconst familyToken: MutableAtomFamilyToken<T & Transceiver<any, any, any>, K> =\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `mutable_atom_family`,\n\t\t}\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 ${PRETTY_TOKEN_TYPES[existing.type]} \"${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<StateLifecycleEvent<MutableAtomToken<T>>>()\n\n\tconst familyFunction = (key: K): MutableAtomToken<T> => {\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> = {\n\t\t\tkey: fullKey,\n\t\t\tclass: options.class,\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, timestamp: Date.now() })\n\t\treturn token\n\t}\n\n\tconst atomFamily = Object.assign(familyFunction, familyToken, {\n\t\tclass: options.class,\n\t\tsubject,\n\t\tinstall: (s: Store) => createMutableAtomFamily(s, options),\n\t\tinternalRoles,\n\t}) satisfies MutableAtomFamily<T, K>\n\n\tstore.families.set(options.key, atomFamily)\n\n\tcreateWritablePureSelectorFamily<AsJSON<T>, K>(\n\t\tstore,\n\t\t{\n\t\t\tkey: `${options.key}:JSON`,\n\t\t\tget:\n\t\t\t\t(key) =>\n\t\t\t\t({ get }) =>\n\t\t\t\t\tget(familyToken, key).toJSON(),\n\t\t\tset:\n\t\t\t\t(key) =>\n\t\t\t\t({ set }, newValue) => {\n\t\t\t\t\tset(familyToken, key, options.class.fromJSON(newValue))\n\t\t\t\t},\n\t\t},\n\t\t[`mutable`, `json`],\n\t)\n\n\tnew FamilyTracker(atomFamily, store)\n\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<any, Json.Serializable, Json.Serializable>,\n\tKey extends Canonical,\n>(\n\tmutableAtomFamily: MutableAtomFamilyToken<Core, Key>,\n\tstore: Store,\n): WritablePureSelectorFamily<ReturnType<Core[`toJSON`]>, Key> => {\n\tconst target = newest(store)\n\tconst key = `${mutableAtomFamily.key}:JSON`\n\tconst jsonFamily = target.families.get(key) as WritablePureSelectorFamily<\n\t\tReturnType<Core[`toJSON`]>,\n\t\tKey\n\t>\n\treturn jsonFamily\n}\n","import type {\n\tMutableAtomToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport { parseJson } from \"atom.io/json\"\n\nimport { findInStore } from \"../families\"\nimport { newest } from \"../lineage\"\nimport { type Store, withdraw } from \"../store\"\nimport type { AsJSON, Transceiver } from \"./transceiver\"\n\nexport const getJsonToken = <T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\tmutableAtomToken: MutableAtomToken<T>,\n): WritablePureSelectorToken<AsJSON<T>> => {\n\tif (mutableAtomToken.family) {\n\t\tconst target = newest(store)\n\t\tconst jsonFamilyKey = `${mutableAtomToken.family.key}:JSON`\n\t\tconst jsonFamilyToken: WritablePureSelectorFamilyToken<AsJSON<T>, string> = {\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 = parseJson(mutableAtomToken.family.subKey)\n\t\tconst jsonToken = findInStore(store, family, subKey)\n\t\treturn jsonToken\n\t}\n\tconst token: WritablePureSelectorToken<AsJSON<T>> = {\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 { SignalFrom, Transceiver } from \"./transceiver\"\n\nexport const getUpdateFamily = <\n\tT extends Transceiver<any, Json.Serializable, Json.Serializable>,\n\tK extends string,\n>(\n\tmutableAtomFamily: MutableAtomFamilyToken<T, K>,\n\tstore: Store,\n): AtomFamily<SignalFrom<T>, K> => {\n\tconst target = newest(store)\n\tconst key = `*${mutableAtomFamily.key}`\n\tconst updateFamily: AtomFamily<SignalFrom<T>, K> = target.families.get(\n\t\tkey,\n\t) as AtomFamily<SignalFrom<T>, K>\n\treturn updateFamily\n}\n","import type { MutableAtomToken, RegularAtomToken } from \"atom.io\"\n\nimport type { SignalFrom, Transceiver } from \"./transceiver\"\n\nexport const getUpdateToken = <T extends Transceiver<any, any, any>>(\n\tmutableAtomToken: MutableAtomToken<T>,\n): RegularAtomToken<SignalFrom<T>> => {\n\tconst key = `*${mutableAtomToken.key}`\n\tconst updateToken: RegularAtomToken<SignalFrom<T>> = { 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<\n\tV,\n\tS extends Json.Serializable,\n\tJ extends Json.Serializable,\n> {\n\tREADONLY_VIEW: V\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\ttoJSON: () => J\n}\n\n// biome-ignore format: intersection\nexport type TransceiverConstructor<\n J extends Json.Serializable,\n T extends Transceiver<any, any, J>\n> =\n\t& ( new () => T )\n\t& { fromJSON: (json: J) => T }\n\nexport function isTransceiver(\n\tvalue: unknown,\n): value is Transceiver<any, Json.Serializable, 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\t`cacheUpdateNumber` in value &&\n\t\t`getUpdateNumber` in value &&\n\t\t`READONLY_VIEW` in value &&\n\t\t`toJSON` in value\n\t)\n}\n\nexport type TransceiverMode = `playback` | `record` | `transaction`\n\nexport type SignalFrom<T extends Transceiver<any, any, any>> =\n\tT extends Transceiver<any, infer S, any> ? S : never\n\nexport type AsJSON<T extends Transceiver<any, any, any>> = T extends Transceiver<\n\tany,\n\tany,\n\tinfer J\n>\n\t? J\n\t: never\n\nexport type ConstructorOf<T extends Transceiver<any, any, any>> =\n\tTransceiverConstructor<AsJSON<T>, T>\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\"`]\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\n// The function wants a constructor C\n// - that has a static fromJSON(json) returning an instance of C\n// - and whose instances have toJSON() whose return type matches fromJSON's param\n","import type {\n\tAtomToken,\n\tLogger,\n\tMoleculeCreationEvent,\n\tMoleculeDisposalEvent,\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 { Fn } 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, any, any>>> = new Map()\n\tpublic families: Map<\n\t\tstring,\n\t\t| HeldSelectorFamily<any, any>\n\t\t| MutableAtomFamily<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<Fn>> = new Map()\n\tpublic transactionMeta: TransactionEpoch | TransactionProgress<Fn> = {\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<Fn>>\n\ttransactionApplying: StatefulSubject<TransactionProgress<Fn> | null>\n\toperationClose: Subject<OperationProgress>\n\tmoleculeCreation: Subject<MoleculeCreationEvent>\n\tmoleculeDisposal: Subject<MoleculeDisposalEvent>\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\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\"\nimport type { internalRole } from \"./has-role\"\n\nexport function createRegularAtom<T>(\n\tstore: Store,\n\toptions: RegularAtomOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tinternalRoles?: internalRole[],\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\tif (internalRoles) {\n\t\tnewAtom.internalRoles = internalRoles\n\t}\n\ttarget.atoms.set(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\tstore.on.atomCreation.next(token)\n\treturn token\n}\n","import type { AtomDisposalEvent, AtomToken, StateLifecycleEvent } from \"atom.io\"\n\nimport type { Store, Subject } from \"..\"\nimport { getUpdateToken, isChildStore, newest, withdraw } from \"..\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\n\nexport function disposeAtom(store: Store, atomToken: AtomToken<any>): 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 familyToken = getFamilyOfToken(store, atomToken)\n\t\tconst atomFamily = withdraw(store, familyToken)\n\t\tconst subject = atomFamily.subject as Subject<\n\t\t\tStateLifecycleEvent<AtomToken<any>>\n\t\t>\n\n\t\tconst disposal: AtomDisposalEvent<AtomToken<any>> = {\n\t\t\ttype: `state_disposal`,\n\t\t\tsubType: `atom`,\n\t\t\ttoken: atomToken,\n\t\t\tvalue: lastValue,\n\t\t\ttimestamp: Date.now(),\n\t\t}\n\n\t\tsubject.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\ttarget.moleculeData.delete(family.key, family.subKey)\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.subEvents.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.subEvents.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 { Atom } from \"..\"\n\nexport const INTERNAL_ROLES = [`tracker:signal`] as const\nexport type internalRole = (typeof INTERNAL_ROLES)[number]\n\nexport function hasRole(atom: Atom<any>, role: internalRole): boolean {\n\tif (`internalRoles` in atom === false) {\n\t\treturn false\n\t}\n\n\treturn atom.internalRoles.includes(role)\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 { 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.token.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.token.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 {\n\tCompoundTypedKey,\n\tfindState,\n\tgetState,\n\tJoinOptions,\n\tMutableAtomFamilyToken,\n\tRead,\n\tReadonlyPureSelectorFamilyToken,\n\tRegularAtomFamilyToken,\n\tsetState,\n\tViewOf,\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 { 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<SetRTX<string>, string>\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<SetRTX<string>, string>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tclass: SetRTX,\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) => ViewOf<Content> | null> = (\n\t\t\t\t{ get },\n\t\t\t\tkey,\n\t\t\t) => get(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, ViewOf<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, ViewOf<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 { JoinOptions, JoinToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { Join } from \"./join-internal\"\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 { 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 } 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>, 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\tAtomUpdateEvent,\n\tStateCreationEvent,\n\tStateDisposalEvent,\n\tTimelineEvent,\n\tTimelineManageable,\n\tTimelineOptions,\n\tTimelineToken,\n\tTransactionOutcomeEvent,\n\tTransactionSubEvent,\n\tTransactionToken,\n} from \"atom.io\"\n\nimport { reduceReference } from \"../get-state/reduce-reference\"\nimport { newest } from \"../lineage\"\nimport { getUpdateToken } from \"../mutable\"\nimport { deposit, type Store, withdraw } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { isChildStore } from \"../transaction\"\n\nexport type Timeline<ManagedAtom extends TimelineManageable> = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\tshouldCapture?: (\n\t\tupdate: TimelineEvent<ManagedAtom>,\n\t\ttimeline: Timeline<ManagedAtom>,\n\t) => boolean\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineEvent<ManagedAtom>[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: Store) => void\n\tsubject: Subject<TimelineEvent<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\treduceReference(store, atomToken)\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 currentSelectorToken =\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\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.timestamp\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.token.key}\"`\n\t\t\t\t\t\t: currentSelectorToken\n\t\t\t\t\t\t\t? `in selector \"${currentSelectorToken.key}\"`\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 (currentSelectorToken && currentSelectorTime) {\n\t\t\t\t\t\tlet latestUpdate: TimelineEvent<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\t// key: currentSelectorKey,\n\t\t\t\t\t\t\t\ttoken: currentSelectorToken,\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\ttype: `atom_update`,\n\t\t\t\t\t\t\t\ttoken: atomToken,\n\t\t\t\t\t\t\t\tupdate,\n\t\t\t\t\t\t\t\ttimestamp: Date.now(), // 👺 use store operation\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 \"${currentSelectorToken.key}\" with`,\n\t\t\t\t\t\t\t\tlatestUpdate.atomUpdates.map(\n\t\t\t\t\t\t\t\t\t(atomUpdate) => atomUpdate.token.key,\n\t\t\t\t\t\t\t\t),\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\ttype: `atom_update`,\n\t\t\t\t\t\t\t\t\ttoken: atomToken,\n\t\t\t\t\t\t\t\t\tupdate,\n\t\t\t\t\t\t\t\t\ttimestamp: Date.now(), // 👺 use store operation\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 \"${currentSelectorToken.key}\" to`,\n\t\t\t\t\t\t\t\t\tlatestUpdate?.atomUpdates.map(\n\t\t\t\t\t\t\t\t\t\t(atomUpdate) => atomUpdate.token.key,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\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: AtomUpdateEvent<any> = {\n\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\ttoken: deposit(atom),\n\t\t\t\t\t\t\tupdate,\n\t\t\t\t\t\t\ttimestamp,\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: TransactionOutcomeEvent<TransactionToken<any>>,\n) {\n\tconst currentTxKey = txUpdateInProgress.token.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 subEventsFiltered = filterTransactionSubEvents(\n\t\t\t\t\t\ttransactionUpdate.subEvents,\n\t\t\t\t\t\ttimelineTopics,\n\t\t\t\t\t)\n\n\t\t\t\t\tconst timelineTransactionUpdate: TransactionOutcomeEvent<\n\t\t\t\t\t\tTransactionToken<any>\n\t\t\t\t\t> = {\n\t\t\t\t\t\t...transactionUpdate,\n\t\t\t\t\t\tsubEvents: subEventsFiltered,\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 filterTransactionSubEvents(\n\tupdates: TransactionSubEvent[],\n\ttimelineTopics: Set<string>,\n): TransactionSubEvent[] {\n\treturn updates\n\t\t.filter((updateFromTx) => {\n\t\t\tif (updateFromTx.type === `transaction_outcome`) {\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 `atom_update`:\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}\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): TransactionSubEvent => {\n\t\t\tif (`subEvents` in updateFromTx) {\n\t\t\t\treturn {\n\t\t\t\t\t...updateFromTx,\n\t\t\t\t\tsubEvents: filterTransactionSubEvents(\n\t\t\t\t\t\tupdateFromTx.subEvents,\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: StateCreationEvent<any> | StateDisposalEvent<any>,\n\ttl: Timeline<any>,\n): void {\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(event)\n\t\t\t\ttl.at = tl.history.length\n\t\t\t\ttl.subject.next(event)\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_outcome`: {\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,UAAU,SAAuB,KAAK,QAAgB;AACrE,QAAO,SAAS,SAAS,IAAI,MAAM;AACnC;;;;ACID,SAAgB,OAA0B,OAAa;AACtD,QAAO,MAAM,UAAU,KACtB,SAAQ,MAAM;AAEf,QAAO;AACP;;;;ACXD,IAAa,iBAAb,MAAa,eAAkB;CAC9B,AAAU;CACV,AAAU,SAAS;CAGnB,AAAO,YAAY,eAA6B;EAC/C,IAAIA;AACJ,MAAI,OAAO,kBAAkB,SAC5B,UAAS;MAET,UAAS,cAAc;AAExB,OAAK,UAAU,MAAM,KAAK,EAAE,QAAQ;CACpC;CAED,IAAW,SAAuC;AACjD,SAAO,KAAK;CACZ;CAED,IAAW,QAAgB;AAC1B,SAAO,KAAK;CACZ;CAED,AAAO,IAAI,MAAe;AACzB,OAAK,QAAQ,KAAK,UAAU;AAC5B,OAAK,UAAU,KAAK,SAAS,KAAK,KAAK,QAAQ;CAC/C;CAED,AAAO,OAA0B;EAChC,MAAM,OAAO,IAAI,eAAkB,CAAC,GAAG,KAAK,QAAQ;AACpD,OAAK,SAAS,KAAK;AACnB,SAAO;CACP;AACD;;;;AC6DD,SAAgB,QAAQ,OAA4C;CACnE,MAAM,QAAQ;EACb,KAAK,MAAM;EACX,MAAM,MAAM;EACZ;AACD,KAAI,YAAY,MACf,OAAM,SAAS,MAAM;AAEtB,QAAO;AACP;;;;AChFD,MAAaC,cAA6B,OAAO;AAEjD,MAAa,4BAA4B;CACxC,aAAa;CACb,iBAAi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