atom.io 0.41.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/internal/index.d.ts +21 -38
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +82 -263
- package/dist/internal/index.js.map +1 -1
- package/dist/main/index.d.ts +18 -36
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +13 -2
- package/dist/main/index.js.map +1 -1
- package/dist/realtime/index.d.ts +2 -3
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +1 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-server/index.js +1 -1
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.js +1 -1
- package/dist/struct/index.d.ts +14 -0
- package/dist/struct/index.d.ts.map +1 -0
- package/dist/struct/index.js +35 -0
- package/dist/struct/index.js.map +1 -0
- package/dist/transceivers/o-list/index.d.ts +10 -6
- package/dist/transceivers/o-list/index.d.ts.map +1 -1
- package/dist/transceivers/o-list/index.js +170 -169
- package/dist/transceivers/o-list/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +1 -0
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/dist/transceivers/u-list/index.d.ts +10 -6
- package/dist/transceivers/u-list/index.d.ts.map +1 -1
- package/dist/transceivers/u-list/index.js +23 -22
- package/dist/transceivers/u-list/index.js.map +1 -1
- package/dist/utility-types-aZkJVERa.d.ts +10 -0
- package/dist/utility-types-aZkJVERa.d.ts.map +1 -0
- package/package.json +13 -9
- package/src/internal/index.ts +0 -1
- package/src/internal/join/create-join.ts +8 -11
- package/src/internal/join/edit-relations-in-store.ts +6 -8
- package/src/internal/join/find-relations-in-store.ts +11 -67
- package/src/internal/join/get-internal-relations-from-store.ts +11 -5
- package/src/internal/join/get-join.ts +7 -9
- package/src/internal/join/join-internal.ts +154 -394
- package/src/internal/mutable/transceiver.ts +1 -5
- package/src/internal/set-state/dispatch-state-update.ts +1 -1
- package/src/internal/store/store.ts +1 -1
- package/src/main/join.ts +68 -151
- package/src/main/realm.ts +4 -4
- package/src/realtime/shared-room-store.ts +5 -15
- package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +1 -1
- package/src/struct/index.ts +1 -0
- package/src/{internal → struct}/micro.ts +1 -1
- package/src/transceivers/o-list/o-list.ts +175 -171
- package/src/transceivers/set-rtx/set-rtx.ts +4 -0
- package/src/transceivers/u-list/u-list.ts +37 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["superResolve: ((value: T) => void) | undefined","superReject: ((reason?: any) => void) | undefined","length: number","a: A | undefined","b: B | undefined","a: A","b: B","content: Content | undefined","singleRelation: A | B | undefined","config: JunctionAdvancedConfiguration<AName, A, BName, B, Content>","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: (\n\t\t| AtomUpdateEvent<AtomOnly<TimelineManageable>>\n\t\t| StateCreationEvent<any>\n\t)[]","childBase: Omit<ChildStore, `transactionMeta`>","transactionMeta: TransactionProgress<Fn>","child: ChildStore","newTransaction: Transaction<F>","token","IMPLICIT: { readonly STORE: RootStore }","withdrawn: AtomIOInternalResource | undefined","target: Store | null","val: E | T","def: E | T","MUST_CREATE: unique symbol","DO_NOT_CREATE: unique symbol","token: ReadableToken<T, KK, E>","existingToken: ReadableToken<T, K, E> | undefined","brandNewToken: ReadableToken<T, K, E> | undefined","family: ReadableFamily<T, K, E> | undefined","subKey: K | undefined","token: ReadableToken<T, K, E>","subType: `readable` | `writable`","stateCreationEvent: StateCreationEvent<any>","state: ReadableState<any, any> | undefined","family: FamilyMetadata<Key>","individualOptions: ReadonlyPureSelectorOptions<T, E>","readonlySelectorFamily: ReadonlyPureSelectorFamily<T, K, E>","familyToken: RegularAtomFamilyToken<T, K, E>","family: FamilyMetadata<Key>","individualOptions: RegularAtomOptions<T, E>","atomFamily: RegularAtomFamily<T, K, E>","atomFamily","family: FamilyMetadata","readonlySelectorFamily: ReadonlyHeldSelectorFamily<T, K>","family: FamilyMetadata","selectorFamily: WritableHeldSelectorFamily<T, K>","selectorFamily","family: FamilyMetadata<Key>","individualOptions: WritablePureSelectorOptions<T, E>","selectorFamily: WritablePureSelectorFamily<T, K, E>","selectorFamily","token: ReadableToken<any, any, any>","stateCreationEvent: StateCreationEvent<any> & TimelineEvent<any>","update: StateUpdate<T>","atomUpdate: AtomUpdateEvent<any>","def: E | T","protoUpdate: ProtoUpdate<E | T>","RESET_STATE: unique symbol","oldValue: T","newValue: T","constant: T","protoUpdate: ProtoUpdate<T>","OWN_OP: unique symbol","JOIN_OP: unique symbol","existingToken: WritableToken<T, K, E> | undefined","brandNewToken: WritableToken<T, K, E> | undefined","token: WritableToken<T, K, E>","family: WritableFamily<T, K, E> | undefined","key: K | null","value: Setter<TT> | TT | typeof RESET_STATE","target: Store & { operation: OpenOperation }","protoUpdate: ProtoUpdate<E | T>","dependencyValue: unknown","readonlySelector: ReadonlyHeldSelector<T>","token: ReadonlyHeldSelectorToken<T>","readonlySelector: ReadonlyPureSelector<T, E>","token: ReadonlyPureSelectorToken<T>","mySelector: WritableHeldSelector<T>","token: WritableHeldSelectorToken<T>","mySelector: WritablePureSelector<T, E>","token: WritablePureSelectorToken<T>","state","familyToken: SelectorFamilyToken<any, any, any>","unsubscribe","updateHandler: UpdateHandler<E | T>","familyMetaData: FamilyMetadata | undefined","newAtom: MutableAtom<T>","cleanupFunctions: (() => void)[]","familyToken: MutableAtomFamilyToken<T & Transceiver<any, any, any>, K>","family: FamilyMetadata","individualOptions: MutableAtomOptions<T>","atomFamily: MutableAtomFamily<T, K>","atomFamily","jsonFamilyToken: WritablePureSelectorFamilyToken<AsJSON<T>, string>","updateToken: RegularAtomToken<SignalFrom<T>>","mutableAtom","newAtom: RegularAtom<T, E>","cleanupFunctions: (() => void)[]","disposalEvent: AtomDisposalEvent<AtomToken<any, any, 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>","relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>","result: Record<any, any>","tl: Timeline<ManagedAtom>","atomToken: AtomToken<any, any, any>","familyToken: AtomFamilyToken<any, any, any>","token: TimelineToken<ManagedAtom>","atomUpdate: AtomUpdateEvent<any> & TimelineEvent<any>","timelineTransactionUpdate: TimelineEvent<any> &\n\t\t\t\t\t\tTransactionOutcomeEvent<TransactionToken<any>>","latestUpdate: TimelineEvent<any> | undefined","selectorUpdate: TimelineEvent<any> & TimelineSelectorUpdateEvent<any>","key: string","familyKey: string | undefined","events: TimelineEvent<any>[]"],"sources":["../../src/internal/arbitrary.ts","../../src/internal/lineage.ts","../../src/internal/is-fn.ts","../../src/internal/set-state/become.ts","../../src/internal/future.ts","../../src/internal/subject.ts","../../src/internal/store/circular-buffer.ts","../../src/internal/store/deposit.ts","../../src/internal/overlays/map-overlay.ts","../../src/internal/overlays/set-overlay.ts","../../src/internal/overlays/relations-overlay.ts","../../src/internal/junction.ts","../../src/internal/reserved-keys.ts","../../src/internal/transaction/abort-transaction.ts","../../src/internal/transaction/act-upon-store.ts","../../src/internal/events/ingest-atom-update.ts","../../src/internal/get-trace.ts","../../src/internal/molecule.ts","../../src/internal/events/ingest-creation-disposal.ts","../../src/internal/events/ingest-selector-update.ts","../../src/internal/events/ingest-transaction-update.ts","../../src/internal/transaction/is-root-store.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/transaction/build-transaction.ts","../../src/internal/transaction/create-transaction.ts","../../src/internal/transaction/transaction-meta-progress.ts","../../src/internal/store/store.ts","../../src/internal/not-found-error.ts","../../src/internal/store/withdraw.ts","../../src/internal/get-state/get-fallback.ts","../../src/internal/safe-compute.ts","../../src/internal/get-state/read-or-compute-value.ts","../../src/internal/families/get-family-of-token.ts","../../src/internal/families/mint-in-store.ts","../../src/internal/get-state/reduce-reference.ts","../../src/internal/get-state/get-from-store.ts","../../src/internal/families/seek-in-store.ts","../../src/internal/families/find-in-store.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/dispose-from-store.ts","../../src/internal/operation.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/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/subscribe/recall-state.ts","../../src/internal/subscribe/subscribe-to-root-atoms.ts","../../src/internal/subscribe/subscribe-to-state.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/caching.ts","../../src/internal/set-state/evict-downstream.ts","../../src/internal/atom/create-regular-atom.ts","../../src/internal/atom/has-role.ts","../../src/internal/atom/dispose-atom.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/micro.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>(\n\tscion: T,\n): Exclude<T[`child`], null> | T {\n\twhile (scion.child !== null) {\n\t\tscion = scion.child\n\t}\n\treturn scion\n}\n\nexport function eldest<T extends Lineage>(\n\tscion: T,\n): Exclude<T[`parent`], T[`child`] | null> {\n\twhile (scion.parent !== null) {\n\t\tscion = scion.parent\n\t}\n\treturn scion as Exclude<T[`parent`], T[`child`] | null>\n}\n","import type { Fn } from \"./utility-types\"\n\nconst NON_CTOR_FN_REGEX =\n\t/^\\[object (?:Async|Generator|AsyncGenerator)?Function\\]$/\n\nexport function isFn(input: unknown): input is Fn {\n\tconst protoString = Object.prototype.toString.call(input)\n\treturn NON_CTOR_FN_REGEX.test(protoString)\n}\n","import { isFn } from \"../is-fn\"\n\nexport function become<T>(\n\tnextVersionOfThing: T | ((prev: T) => T),\n\toriginalThing: T,\n): T {\n\tif (isFn(nextVersionOfThing)) {\n\t\treturn nextVersionOfThing(originalThing)\n\t}\n\treturn nextVersionOfThing\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","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","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 { Transceiver } from \"../mutable\"\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tMutableAtom,\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadableState,\n\tReadonlyPureSelector,\n\tReadonlyPureSelectorFamily,\n\tRegularAtom,\n\tRegularAtomFamily,\n\tSelector,\n\tSelectorFamily,\n\tWritableFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableState,\n} from \"../state-types\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Fn } from \"../utility-types\"\n\nexport function deposit<T, E>(\n\tstate: RegularAtom<T, E>,\n): RegularAtomToken<T, Canonical, E>\nexport function deposit<T extends Transceiver<any, any, any>>(\n\tstate: MutableAtom<T>,\n): MutableAtomToken<T>\nexport function deposit<T, E>(state: Atom<T, E>): AtomToken<T, Canonical, E>\nexport function deposit<T, E>(\n\tstate: WritablePureSelector<T, E>,\n): WritablePureSelectorToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadonlyPureSelector<T, E>,\n): ReadonlyPureSelectorToken<T, any, E>\nexport function deposit<T, E>(state: Selector<T, E>): SelectorToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: WritableState<T, E>,\n): WritableToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadableState<T, E>,\n): ReadableToken<T, any, E>\n\nexport function deposit<T, K extends Canonical, E>(\n\tstate: RegularAtomFamily<T, K, E>,\n): RegularAtomFamilyToken<T, K, E>\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, E>(\n\tstate: AtomFamily<T, any, E>,\n): AtomFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: WritablePureSelectorFamily<T, any, E>,\n): WritablePureSelectorFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadonlyPureSelectorFamily<T, any, E>,\n): ReadonlyPureSelectorFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: SelectorFamily<T, any, E>,\n): SelectorFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: WritableFamily<T, any, E>,\n): WritableFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadableFamily<T, any, E>,\n): ReadableFamilyToken<T, any, E>\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","export class MapOverlay<K, V> extends Map<K, V> {\n\tpublic deleted: Set<K> = new Set()\n\tpublic changed: 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\tif (this.source.has(key)) {\n\t\t\tthis.changed.add(key)\n\t\t}\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\tif (this.source.has(key)) {\n\t\t\tthis.deleted.add(key)\n\t\t\tthis.changed.delete(key)\n\t\t}\n\t\treturn super.delete(key)\n\t}\n\n\tpublic clear(): void {\n\t\tthis.deleted = new Set(this.source.keys())\n\t\tthis.changed.clear()\n\t\tsuper.clear()\n\t}\n\n\tpublic *[Symbol.iterator](): MapIterator<[K, V]> {\n\t\tyield* super[Symbol.iterator]()\n\t\tfor (const [key, value] of this.source) {\n\t\t\tif (!this.deleted.has(key) && !this.changed.has(key)) {\n\t\t\t\tyield [key, value]\n\t\t\t}\n\t\t}\n\t}\n\tpublic *entries(): MapIterator<[K, V]> {\n\t\tyield* this[Symbol.iterator]()\n\t}\n\tpublic *keys(): MapIterator<K> {\n\t\tyield* super.keys()\n\t\tfor (const key of this.source.keys()) {\n\t\t\tif (!this.deleted.has(key) && !this.changed.has(key)) {\n\t\t\t\tyield key\n\t\t\t}\n\t\t}\n\t}\n\tpublic *values(): MapIterator<V> {\n\t\tfor (const [, value] of this[Symbol.iterator]()) {\n\t\t\tyield value\n\t\t}\n\t}\n\tpublic forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void): void {\n\t\tfor (const [key, value] of this[Symbol.iterator]()) {\n\t\t\tcallbackfn(value, key, this)\n\t\t}\n\t}\n\n\tpublic get size(): number {\n\t\treturn super.size + this.source.size - this.changed.size - this.deleted.size\n\t}\n}\n","export class SetOverlay<T> extends Set<T> {\n\tpublic deleted: Set<T> = new Set()\n\tpublic source: Set<T>\n\n\tpublic constructor(source: Set<T>) {\n\t\tsuper()\n\t\tthis.source = source\n\t}\n\n\tpublic add(value: T): this {\n\t\tif (this.source.has(value)) {\n\t\t\tthis.deleted.delete(value)\n\t\t\treturn this\n\t\t}\n\t\treturn super.add(value)\n\t}\n\n\tpublic hasOwn(member: T): boolean {\n\t\treturn super.has(member)\n\t}\n\n\tpublic has(key: T): boolean {\n\t\treturn !this.deleted.has(key) && (super.has(key) || this.source.has(key))\n\t}\n\n\tpublic delete(key: T): boolean {\n\t\tif (this.source.has(key)) {\n\t\t\tthis.deleted.add(key)\n\t\t\treturn true\n\t\t}\n\t\treturn super.delete(key)\n\t}\n\n\tpublic clear(): void {\n\t\tthis.deleted = new Set(this.source)\n\t\tsuper.clear()\n\t}\n\n\tpublic *[Symbol.iterator](): SetIterator<T> {\n\t\tyield* super[Symbol.iterator]()\n\t\tfor (const value of this.source) {\n\t\t\tif (!this.deleted.has(value)) {\n\t\t\t\tyield value\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic *iterateOwn(): SetIterator<T> {\n\t\tyield* super[Symbol.iterator]()\n\t}\n\n\tpublic get size(): number {\n\t\treturn super.size + this.source.size - this.deleted.size\n\t}\n}\n","import { SetOverlay } from \"./set-overlay\"\n\nexport class RelationsOverlay<K, V extends Set<any>> 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\tconst valueOverlay = new SetOverlay(value as V) as unknown as V\n\t\t\tsuper.set(key, valueOverlay)\n\t\t\treturn valueOverlay\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 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 { Json } from \"atom.io/json\"\n\nimport { MapOverlay, RelationsOverlay, SetOverlay } from \"./overlays\"\nimport type { Refinement } from \"./utility-types\"\n\nexport type JunctionEntriesBase<\n\tA extends string,\n\tB extends string,\n\tContent extends Json.Object | null,\n> = {\n\treadonly relations: ([A, B[]] | [B, A[]])[]\n\treadonly contents: [string, Content][]\n}\nexport interface JunctionEntries<\n\tA extends string,\n\tB extends string,\n\tContent extends Json.Object | null,\n> extends Json.Object,\n\t\tJunctionEntriesBase<A, B, Content> {}\n\nexport type JunctionSchemaBase<AName extends string, BName extends string> = {\n\t/** Description of the relationship between the two sides */\n\treadonly between: [a: AName, b: BName]\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\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tContent extends Json.Object | null,\n> = {\n\twarn?: (...args: any[]) => void\n\texternalStore?: ExternalStoreConfiguration<Content>\n\tisAType?: Refinement<string, A>\n\tisBType?: Refinement<string, B>\n\tisContent?: Refinement<unknown, Content>\n\tmakeContentKey?: (a: A, b: B) => string\n\tsource?: Junction<AName, A, BName, B, Content>\n}\n\nexport type JunctionJSON<\n\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tContent extends Json.Object | null,\n> = JunctionEntries<A, B, Content> & JunctionSchema<AName, BName>\n\nexport class Junction<\n\tconst AName extends string,\n\tconst A extends string,\n\tconst BName extends string,\n\tconst B extends string,\n\tconst Content extends Json.Object | null = null,\n> {\n\tpublic readonly a: AName\n\tpublic readonly b: BName\n\tpublic readonly cardinality: `1:1` | `1:n` | `n:n`\n\tpublic readonly relations: Map<A | B, Set<A> | Set<B>> = new Map()\n\tpublic readonly contents: Map<string, Content> = new Map()\n\n\tpublic isAType?: Refinement<string, A> | null\n\tpublic isBType?: Refinement<string, B> | null\n\tpublic isContent: Refinement<unknown, Content> | null\n\tpublic makeContentKey = (a: A, b: B): string => `${a}:${b}`\n\n\tpublic warn?: (...args: any[]) => void\n\n\tpublic getRelatedKeys(key: A): Set<B> | undefined\n\tpublic getRelatedKeys(key: B): Set<A> | undefined\n\tpublic getRelatedKeys(key: A | B): Set<A> | Set<B> | undefined\n\tpublic getRelatedKeys(key: A | B): Set<A> | Set<B> | undefined {\n\t\treturn this.relations.get(key)\n\t}\n\tprotected addRelation(a: A, b: B): void {\n\t\tlet aRelations = this.relations.get(a) as Set<B> | undefined\n\t\tlet bRelations = this.relations.get(b) as Set<A> | 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: A, b: B): void {\n\t\tconst aRelations = this.relations.get(a) as Set<B> | 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<A> | 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: A, bs: B[]): void\n\tprotected replaceRelationsUnsafely(b: B, as: A[]): void\n\tprotected replaceRelationsUnsafely(x: A | B, ys: A[] | B[]): void {\n\t\tthis.relations.set(x as A, new Set(ys as B[]))\n\t\tfor (const y of ys) {\n\t\t\tconst yRelations = new Set<A>().add(x as A)\n\t\t\tthis.relations.set(y, yRelations)\n\t\t}\n\t}\n\tprotected replaceRelationsSafely(a: A, bs: B[]): void\n\tprotected replaceRelationsSafely(b: B, as: A[]): void\n\tprotected replaceRelationsSafely<\n\t\tXType extends A | B,\n\t\tYType extends XType extends A ? B : A,\n\t>(x: XType, ys: YType[]): void {\n\t\tconst xRelationsPrev = this.relations.get(x)\n\t\tlet a: A | undefined = this.isAType?.(x) ? x : undefined\n\t\tlet b: B | undefined = a === undefined ? (x as B) : undefined\n\t\tif (xRelationsPrev) {\n\t\t\tfor (const y of xRelationsPrev) {\n\t\t\t\ta ??= y as A\n\t\t\t\tb ??= y as B\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<AName, BName> &\n\t\t\tPartial<JunctionEntries<NoInfer<A>, NoInfer<B>, Content>>,\n\t\tconfig?: JunctionAdvancedConfiguration<AName, A, BName, B, 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\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 source = config?.source\n\t\t\tif (source === undefined) {\n\t\t\t\tthis.relations = new Map(\n\t\t\t\t\tdata.relations?.map(([x, ys]) => [x, new Set(ys as A[])]),\n\t\t\t\t)\n\t\t\t\tthis.contents = new Map(data.contents)\n\t\t\t}\n\t\t\tif (source) {\n\t\t\t\tthis.relations = new RelationsOverlay(source.relations)\n\t\t\t\tthis.contents = new MapOverlay(source.contents)\n\t\t\t}\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 B) : undefined\n\t\t\t\tfor (const y of ys) {\n\t\t\t\t\ta ??= y as A\n\t\t\t\t\tb ??= y as B\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<AName, A, BName, B, 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 [A, B[]],\n\t\t\t),\n\t\t\tcontents: [...this.contents.entries()],\n\t\t}\n\t}\n\n\tpublic set(\n\t\ta: A,\n\t\t...rest: Content extends null ? [b: B] : [b: B, content: Content]\n\t): this\n\tpublic set(\n\t\trelation: { [Key in AName]: A } & { [Key in BName]: B },\n\t\t...rest: Content extends null ? [] | [void?: undefined] : [content: Content]\n\t): this\n\tpublic set(\n\t\t...params:\n\t\t\t| [\n\t\t\t\t\trelation: { [Key in AName]: A } & { [Key in BName]: B },\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\t| [a: A, ...rest: Content extends null ? [b: B] : [b: B, content: Content]]\n\t): this {\n\t\tlet a: A\n\t\tlet b: B\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<AName, A> & Record<BName, B>\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 [A, B]\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 A\n\t\t\t\tb = params[1] as B\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: A, b?: B): this\n\tpublic delete(b: B, a?: A): this\n\tpublic delete(\n\t\trelation:\n\t\t\t| { [Key in AName]: A }\n\t\t\t| { [Key in BName]: B }\n\t\t\t| ({ [Key in AName]: A } & { [Key in BName]: B }),\n\t\tb?: undefined,\n\t): this\n\tpublic delete(\n\t\tx:\n\t\t\t| A\n\t\t\t| B\n\t\t\t| Record<AName | BName, string>\n\t\t\t| Record<AName, string>\n\t\t\t| Record<BName, string>,\n\t\tb?: A | B,\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 B) : (x[this.b] as B | 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 A) : (x[this.a] as A | undefined)\n\n\t\tif (a === undefined && typeof b === `string`) {\n\t\t\tconst bRelations = this.getRelatedKeys(b) as Set<A>\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} else if (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} else if (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: A): B | undefined\n\tpublic getRelatedKey(key: B): A | undefined\n\tpublic getRelatedKey(key: A | B): A | B | 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: A | B | 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: A,\n\t\trelations: Content extends null ? B[] : Record<B, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this\n\tpublic replaceRelations(\n\t\tb: B,\n\t\trelations: Content extends null ? A[] : Record<A, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this\n\tpublic replaceRelations<\n\t\tXType extends A | B,\n\t\tYType extends XType extends A ? B : A,\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: A, b: B): Content | undefined {\n\t\tconst contentKey = this.makeContentKey(a, b)\n\t\treturn this.getContentInternal(contentKey)\n\t}\n\n\tpublic getRelationEntries(input: Record<AName, A>): [B, Content][]\n\tpublic getRelationEntries(input: Record<BName, B>): [A, Content][]\n\tpublic getRelationEntries(\n\t\tinput: Record<AName, A> | Record<BName, B>,\n\t): [A | B, Content][] {\n\t\tconst a: A | undefined = (input as any)[this.a]\n\t\tconst b: B | 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: A, b?: B): boolean\n\tpublic has(b: B, a?: A): boolean\n\tpublic has(a: A | B, b?: A | B): 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\tpublic overlay(): JunctionOverlay<AName, A, BName, B, Content> {\n\t\tconst config: JunctionAdvancedConfiguration<AName, A, BName, B, Content> = {\n\t\t\tsource: this,\n\t\t\tmakeContentKey: this.makeContentKey,\n\t\t}\n\t\tif (this.isAType) config.isAType = this.isAType\n\t\tif (this.isBType) config.isBType = this.isBType\n\t\tif (this.isContent) config.isContent = this.isContent\n\t\tif (this.warn) config.warn = this.warn\n\n\t\treturn new Junction(\n\t\t\t{\n\t\t\t\tbetween: [this.a, this.b],\n\t\t\t\tcardinality: this.cardinality,\n\t\t\t},\n\t\t\tconfig,\n\t\t) as JunctionOverlay<AName, A, BName, B, Content>\n\t}\n\tpublic incorporate(\n\t\toverlay: JunctionOverlay<AName, A, BName, B, Content>,\n\t): void {\n\t\tconst { relations, contents } = overlay\n\t\tfor (const [key, value] of relations) {\n\t\t\tif (value instanceof SetOverlay) {\n\t\t\t\tconst { source } = value\n\t\t\t\tfor (const keyAdded of value.iterateOwn()) {\n\t\t\t\t\tsource.add(keyAdded)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.relations.set(key, value)\n\t\t\t}\n\t\t}\n\t\tfor (const key of relations.deleted) {\n\t\t\tthis.relations.delete(key)\n\t\t}\n\t\tfor (const [key, value] of contents) {\n\t\t\tthis.contents.set(key, value)\n\t\t}\n\t\tfor (const key of contents.deleted) {\n\t\t\tthis.contents.delete(key)\n\t\t}\n\t}\n}\n\nexport type JunctionOverlay<\n\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tContent extends Json.Object | null = null,\n> = Junction<AName, A, BName, B, Content> & {\n\trelations: MapOverlay<A | B, Set<A> | Set<B>>\n\tcontents: MapOverlay<string, Content>\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 { ChildStore } from \"./is-root-store\"\n\nexport const abortTransaction = (target: ChildStore): void => {\n\ttarget.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 { TransactionToken } from \"atom.io\"\n\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\treturn tx.run(parameters, id)\n\t}\n}\n","import type { AtomUpdateEvent } from \"atom.io\"\n\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\n\nexport function ingestAtomUpdateEvent(\n\tstore: Store,\n\tevent: AtomUpdateEvent<any>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tconst {\n\t\ttoken,\n\t\tupdate: { newValue, oldValue },\n\t} = event\n\tconst value = applying === `newValue` ? newValue : oldValue\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\tTransactionToken,\n\tVassal,\n} from \"atom.io\"\nimport type { Canonical, stringified } from \"atom.io/json\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\n\nimport { disposeFromStore } from \"./families\"\nimport { getFromStore } from \"./get-state\"\nimport { getTrace } from \"./get-trace\"\nimport { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\nimport type { RootStore } from \"./transaction\"\nimport { createTransaction, 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\tstore: Store,\n\tkey: S,\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 createDeallocateTX<\n\tH extends Hierarchy,\n\tV extends Exclude<Vassal<H>, CompoundTypedKey>,\n>(store: RootStore): TransactionToken<(claim: Claim<V>) => void> {\n\treturn createTransaction(store, {\n\t\tkey: `[Internal] deallocate`,\n\t\tdo: (_, claim: Claim<V>): void => {\n\t\t\tdeallocateFromStore<H, V>(newest(store), claim)\n\t\t},\n\t})\n}\n\nexport function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(\n\ttarget: Store,\n\tclaim: Claim<V>,\n): void {\n\tconst stringKey = stringifyJson(claim)\n\n\tconst molecule = target.molecules.get(stringKey)\n\tif (!molecule) {\n\t\tconst disposal = target.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === stringKey,\n\t\t)\n\t\ttarget.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 \"${target.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 = target.moleculeJoins.getRelatedKeys(stringKey)\n\tif (joinKeys) {\n\t\tfor (const joinKey of joinKeys) {\n\t\t\tconst join = target.joins.get(joinKey)\n\t\t\tif (join) {\n\t\t\t\tjoin.relations.delete(claim)\n\t\t\t}\n\t\t}\n\t}\n\ttarget.moleculeJoins.delete(stringKey)\n\n\tconst provenance: stringified<Canonical>[] = []\n\n\tconst values: [string, any][] = []\n\n\tconst relatedMolecules = target.moleculeGraph.getRelationEntries({\n\t\tdownstreamMoleculeKey: stringKey,\n\t})\n\tif (relatedMolecules) {\n\t\tfor (const [relatedStringKey, { source }] of relatedMolecules) {\n\t\t\tif (source === stringKey) {\n\t\t\t\tconst relatedKey = parseJson(relatedStringKey)\n\t\t\t\tdeallocateFromStore<any, any>(target, 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 value = getFromStore(target, family, claim)\n\t\t\tvalues.push([family.key, value])\n\t\t\tdisposeFromStore(target, family, claim)\n\t\t}\n\t}\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\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\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\ttarget.disposalTraces.add({ key: stringKey, trace })\n}\n\nexport function createClaimTX<\n\tH extends Hierarchy,\n\tV extends Exclude<Vassal<H>, CompoundTypedKey>,\n\tA extends Above<V, H>,\n>(\n\tstore: RootStore,\n): TransactionToken<\n\t(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`) => void\n> {\n\treturn createTransaction(store, {\n\t\tkey: `[Internal] claim`,\n\t\tdo: (_, newProvenance, claim, exclusive) => {\n\t\t\tclaimWithinStore<H, V, A>(store, newProvenance, claim, exclusive)\n\t\t},\n\t})\n}\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 { getFromStore } from \"../get-state\"\nimport {\n\tallocateIntoStore,\n\tclaimWithinStore,\n\tdeallocateFromStore,\n} from \"../molecule\"\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\n\nexport function ingestCreationEvent(\n\tstore: Store,\n\tevent: StateCreationEvent<any>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`: {\n\t\t\tcreateInStore(store, event)\n\t\t\tbreak\n\t\t}\n\t\tcase `oldValue`: {\n\t\t\tdisposeFromStore(store, event.token)\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nexport function ingestDisposalEvent(\n\tstore: Store,\n\tevent: StateDisposalEvent<ReadableToken<any, any, any>>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`: {\n\t\t\tdisposeFromStore(store, event.token)\n\t\t\tbreak\n\t\t}\n\t\tcase `oldValue`: {\n\t\t\tcreateInStore(store, event)\n\t\t\tif (event.subType === `atom`) {\n\t\t\t\tstore.valueMap.set(event.token.key, event.value)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nfunction createInStore(\n\tstore: Store,\n\tevent: StateCreationEvent<any> | StateDisposalEvent<any>,\n): void {\n\tconst { token } = event\n\tif (event.subType === `writable` && event.value) {\n\t\tsetIntoStore(store, token, event.value)\n\t} else {\n\t\tgetFromStore(store, token)\n\t}\n}\n\nexport function ingestMoleculeCreationEvent(\n\tstore: Store,\n\tevent: MoleculeCreationEvent,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\tallocateIntoStore<any, any, any>(store, event.provenance, event.key)\n\t\t\tbreak\n\n\t\tcase `oldValue`:\n\t\t\tdeallocateFromStore<any, any>(store, event.key)\n\t\t\tbreak\n\t}\n}\nexport function ingestMoleculeDisposalEvent(\n\tstore: Store,\n\tevent: MoleculeDisposalEvent,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\tdeallocateFromStore<any, any>(store, event.key)\n\t\t\tbreak\n\n\t\tcase `oldValue`:\n\t\t\t{\n\t\t\t\tconst provenanceJson = event.provenance.map(parseJson)\n\t\t\t\tallocateIntoStore<any, any, any>(store, provenanceJson, event.key)\n\t\t\t\tfor (const [familyKey, value] of event.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\tgetFromStore(store, family, event.key)\n\t\t\t\t\t\tconst memberKey = `${familyKey}(${stringifyJson(event.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\tstore: Store,\n\tevent: MoleculeTransferEvent,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\t{\n\t\t\t\tfor (const newOwner of event.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\tevent.key,\n\t\t\t\t\t\tevent.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 event.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\tevent.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\tStateCreationEvent,\n\tTimelineManageable,\n\tTimelineSelectorUpdateEvent,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdateEvent } from \"./ingest-atom-update\"\nimport { ingestCreationEvent } from \"./ingest-creation-disposal\"\n\nexport function ingestSelectorUpdateEvent(\n\tstore: Store,\n\tselectorUpdate: TimelineSelectorUpdateEvent<any>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tlet updates: (\n\t\t| AtomUpdateEvent<AtomOnly<TimelineManageable>>\n\t\t| StateCreationEvent<any>\n\t)[]\n\tif (applying === `newValue`) {\n\t\tupdates = selectorUpdate.subEvents\n\t} else {\n\t\tupdates = selectorUpdate.subEvents.toReversed()\n\t}\n\tfor (const atomUpdate of updates) {\n\t\tif (atomUpdate.type === `state_creation`) {\n\t\t\tingestCreationEvent(store, atomUpdate, applying)\n\t\t} else {\n\t\t\tingestAtomUpdateEvent(store, atomUpdate, applying)\n\t\t}\n\t}\n}\n","import type { TransactionOutcomeEvent } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdateEvent } from \"./ingest-atom-update\"\nimport {\n\tingestCreationEvent,\n\tingestDisposalEvent,\n\tingestMoleculeCreationEvent,\n\tingestMoleculeDisposalEvent,\n\tingestMoleculeTransferEvent,\n} from \"./ingest-creation-disposal\"\n\nexport function ingestTransactionOutcomeEvent(\n\tstore: Store,\n\tevent: TransactionOutcomeEvent<any>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tconst subEvents =\n\t\tapplying === `newValue` ? event.subEvents : [...event.subEvents].reverse()\n\tfor (const subEvent of subEvents) {\n\t\tswitch (subEvent.type) {\n\t\t\tcase `atom_update`:\n\t\t\t\tingestAtomUpdateEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `state_creation`:\n\t\t\t\tingestCreationEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `state_disposal`:\n\t\t\t\tingestDisposalEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `molecule_creation`:\n\t\t\t\tingestMoleculeCreationEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `molecule_disposal`:\n\t\t\t\tingestMoleculeDisposalEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `molecule_transfer`:\n\t\t\t\tingestMoleculeTransferEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `transaction_outcome`:\n\t\t\t\tingestTransactionOutcomeEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t}\n\t}\n}\n","import type { MapOverlay } from \"../overlays/map-overlay\"\nimport type { Store } from \"../store\"\nimport type { Fn } from \"../utility-types\"\nimport type {\n\tTransactionEpoch,\n\tTransactionProgress,\n} from \"./transaction-meta-progress\"\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: MapOverlay<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 { RootStore } 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: RootStore,\n\ttransactionKey: string,\n): number | undefined {\n\tconst continuityKey = getContinuityKey(store, transactionKey)\n\tif (continuityKey === undefined) {\n\t\treturn undefined\n\t}\n\treturn getEpochNumberOfContinuity(store, continuityKey)\n}\n","import { getContinuityKey } from \"./get-epoch-number\"\nimport type { RootStore } from \"./is-root-store\"\n\nexport function setEpochNumberOfContinuity(\n\tstore: RootStore,\n\tcontinuityKey: string,\n\tnewEpoch: number,\n): void {\n\tstore.transactionMeta.epoch.set(continuityKey, newEpoch)\n}\n\nexport function setEpochNumberOfAction(\n\tstore: RootStore,\n\ttransactionKey: string,\n\tnewEpoch: number,\n): void {\n\tconst continuityKey = getContinuityKey(store, transactionKey)\n\n\tif (continuityKey !== undefined) {\n\t\tstore.transactionMeta.epoch.set(continuityKey, newEpoch)\n\t}\n}\n","import { ingestTransactionOutcomeEvent } from \"../events\"\nimport { newest } from \"../lineage\"\nimport { withdraw } from \"../store\"\nimport type { Fn } from \"../utility-types\"\nimport type { ChildStore } from \"./is-root-store\"\nimport { isChildStore, isRootStore } from \"./is-root-store\"\nimport { setEpochNumberOfAction } from \"./set-epoch-number\"\n\nexport function applyTransaction<F extends Fn>(\n\tstore: ChildStore,\n\toutput: ReturnType<F>,\n): void {\n\tconst child = newest(store)\n\tconst { parent } = child\n\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 ${updates.length} subEvents:`,\n\t\tupdates,\n\t)\n\n\tingestTransactionOutcomeEvent(parent, child.transactionMeta.update, `newValue`)\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`applied`,\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 { RootStore } from \"./is-root-store\"\n\nexport function assignTransactionToContinuity(\n\tstore: RootStore,\n\tcontinuityKey: string,\n\ttransactionKey: string,\n): void {\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","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 { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { MapOverlay } from \"../overlays/map-overlay\"\nimport { resetInStore, setIntoStore } from \"../set-state\"\nimport type { Fn } from \"../utility-types\"\nimport { actUponStore } from \"./act-upon-store\"\nimport { getEpochNumberOfAction } from \"./get-epoch-number\"\nimport type { ChildStore, RootStore } from \"./is-root-store\"\nimport type { TransactionProgress } from \"./transaction-meta-progress\"\n\nexport const buildTransaction = (\n\tstore: RootStore,\n\ttoken: TransactionToken<any>,\n\tparams: any[],\n\tid: string,\n): ChildStore => {\n\tconst parent = newest(store)\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 MapOverlay(parent.atoms),\n\t\tatomsThatAreDefault: new Set(parent.atomsThatAreDefault),\n\t\tfamilies: new MapOverlay(parent.families),\n\t\tjoins: new MapOverlay(parent.joins),\n\t\toperation: { open: false },\n\t\treadonlySelectors: new MapOverlay(parent.readonlySelectors),\n\t\ttimelines: new MapOverlay(parent.timelines),\n\t\ttimelineTopics: parent.timelineTopics.overlay(),\n\t\ttrackers: new Map(),\n\t\ttransactions: new MapOverlay(parent.transactions),\n\t\tselectorAtoms: parent.selectorAtoms.overlay(),\n\t\tselectorGraph: parent.selectorGraph.overlay(),\n\t\twritableSelectors: new MapOverlay(parent.writableSelectors),\n\t\tvalueMap: new MapOverlay(parent.valueMap),\n\t\tdefaults: parent.defaults,\n\t\tdisposalTraces: store.disposalTraces.copy(),\n\t\tmolecules: new MapOverlay(parent.molecules),\n\t\tmoleculeGraph: parent.moleculeGraph.overlay(),\n\t\tmoleculeData: parent.moleculeData.overlay(),\n\t\tmoleculeJoins: parent.moleculeJoins.overlay(),\n\t\tmiscResources: new MapOverlay(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 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 { 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\"\nimport type { RootStore } from \"./is-root-store\"\n\nexport type Transaction<F extends Fn> = {\n\tkey: string\n\ttype: `transaction`\n\tinstall: (store: RootStore) => 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: RootStore,\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 target = buildTransaction(store, token, params, id)\n\t\t\ttry {\n\t\t\t\tconst { toolkit } = target.transactionMeta\n\t\t\t\tconst output = options.do(toolkit, ...params)\n\t\t\t\tapplyTransaction<F>(target, output)\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 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\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 { 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 { isReservedIntrospectionKey } from \"../reserved-keys\"\nimport type {\n\tAtom,\n\tHeldSelectorFamily,\n\tMutableAtomFamily,\n\tPureSelectorFamily,\n\tReadonlySelector,\n\tRegularAtomFamily,\n\tWritableSelector,\n} from \"../state-types\"\nimport { StatefulSubject, Subject } from \"../subject\"\nimport type { Timeline } from \"../timeline\"\nimport type {\n\tChildStore,\n\tRootStore,\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: ChildStore | RootStore | null = null\n\tpublic child: ChildStore | 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, any>> = new Map()\n\tpublic writableSelectors: Map<string, WritableSelector<any, any>> = new Map()\n\tpublic readonlySelectors: Map<string, ReadonlySelector<any, 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, any>\n\t\t| RegularAtomFamily<any, 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 as RootStore)\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 as RootStore)\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 as RootStore)\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 as RootStore)\n\t\t\t}\n\t\t\tfor (const [, tx] of store.transactions) {\n\t\t\t\ttx.install(this as RootStore)\n\t\t\t}\n\t\t\tfor (const [, timeline] of store.timelines) {\n\t\t\t\ttimeline.install(this as RootStore)\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport type StoreEventCarrier = {\n\tatomCreation: Subject<AtomToken<unknown, any, any>>\n\tatomDisposal: Subject<AtomToken<unknown, any, any>>\n\tselectorCreation: Subject<SelectorToken<unknown, any, any>>\n\tselectorDisposal: Subject<SelectorToken<unknown, any, any>>\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: RootStore | undefined\n}\n\nexport const IMPLICIT: { readonly STORE: RootStore } = {\n\tget STORE(): RootStore {\n\t\tglobalThis.ATOM_IO_IMPLICIT_STORE ??= new Store({\n\t\t\tname: `IMPLICIT_STORE`,\n\t\t\tlifespan: `ephemeral`,\n\t\t}) as RootStore\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 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 {\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 { Transceiver } from \"../mutable\"\nimport { NotFoundError } from \"../not-found-error\"\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\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\tWritableFamily,\n\tWritableHeldSelector,\n\tWritableHeldSelectorFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableSelector,\n\tWritableSelectorFamily,\n\tWritableState,\n} from \"../state-types\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Fn } from \"../utility-types\"\nimport type { Store } from \"./store\"\n\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, any, E>,\n): RegularAtom<T, E>\nexport function withdraw<T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\ttoken: MutableAtomToken<T, any>,\n): MutableAtom<T>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: AtomToken<T, any, E>,\n): Atom<T, E>\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, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, any, E>,\n): WritablePureSelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, any, E>,\n): ReadonlyPureSelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadonlySelectorToken<T, any, E>,\n): ReadonlySelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: WritableSelectorToken<T, any, E>,\n): WritableSelector<T, E>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: HeldSelectorToken<T>,\n): HeldSelector<T>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: PureSelectorToken<T, any, E>,\n): PureSelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: SelectorToken<T, any, E>,\n): Selector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: WritableToken<T, any, E>,\n): WritableState<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n): ReadableState<T, E>\n\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K, E>,\n): RegularAtomFamily<T, K, E>\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, E>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K, E>,\n): AtomFamily<T, K, E>\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, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K, E>,\n): ReadonlyPureSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K, E>,\n): WritablePureSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadonlySelectorFamilyToken<T, K, E>,\n): ReadonlySelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritableSelectorFamilyToken<T, K, E>,\n): WritableSelectorFamily<T, K, E>\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, E>(\n\tstore: Store,\n\ttoken: PureSelectorFamilyToken<T, K, E>,\n): PureSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K, E>,\n): SelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K, E>,\n): WritableFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K, E>,\n): ReadableFamily<T, K, E>\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, E>(\n\tstore: Store,\n\ttoken: WritableToken<T, any, E>,\n): WritableState<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n): ReadableState<T, E>\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 { ReadableToken, ViewOf } from \"atom.io\"\nimport { type Canonical, stringifyJson } from \"atom.io/json\"\n\nimport type { ReadableFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport function getFallback<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K, E>,\n\tfamily: ReadableFamily<T, K, E>,\n\tsubKey: NoInfer<K>,\n): ViewOf<E | 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.READONLY_VIEW\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 as ViewOf<T>\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 as ViewOf<T>\n\t\t}\n\t}\n}\n","import { writeToCache } from \"./caching\"\nimport { isFn } from \"./is-fn\"\nimport type { PureSelector, RegularAtom } from \"./state-types\"\nimport type { Store } from \"./store\"\n\nexport function safeCompute<T, E>(\n\ttarget: Store,\n\tstate: PureSelector<T, E> | RegularAtom<T, E>,\n): E | T {\n\tconst { type, key, catch: canCatch } = state\n\tswitch (type) {\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_pure_selector`: {\n\t\t\tlet val: E | T\n\t\t\ttarget.logger.info(`🧮`, type, key, `computing value`)\n\t\t\ttry {\n\t\t\t\tval = state.getFrom(target)\n\t\t\t\tif (val instanceof Promise) {\n\t\t\t\t\treturn (val as Promise<E & T>).catch((thrown) => {\n\t\t\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, thrown)\n\t\t\t\t\t\tif (canCatch) {\n\t\t\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\t\t\tif (thrown instanceof Class) {\n\t\t\t\t\t\t\t\t\treturn thrown\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\tthrow thrown\n\t\t\t\t\t}) as E | T\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, e)\n\t\t\t\tif (canCatch) {\n\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\tif (e instanceof Class) {\n\t\t\t\t\t\t\treturn writeToCache(target, state, e)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow e\n\t\t\t}\n\t\t\tconst cachedValue = writeToCache(target, state, val)\n\t\t\treturn cachedValue\n\t\t}\n\t\tcase `atom`: {\n\t\t\tlet def: E | T\n\t\t\tif (isFn(state.default)) {\n\t\t\t\ttry {\n\t\t\t\t\tdef = state.default()\n\t\t\t\t\tif (def instanceof Promise) {\n\t\t\t\t\t\tdef = (def as Promise<T> & T).catch<E | T>((thrown) => {\n\t\t\t\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, thrown)\n\t\t\t\t\t\t\tif (canCatch) {\n\t\t\t\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\t\t\t\tif (thrown instanceof Class) {\n\t\t\t\t\t\t\t\t\t\treturn thrown\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\tthrow thrown\n\t\t\t\t\t\t}) as E | T\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, e)\n\t\t\t\t\tif (canCatch) {\n\t\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\t\tif (e instanceof Class) {\n\t\t\t\t\t\t\t\tdef = writeToCache(target, state, e)\n\t\t\t\t\t\t\t\ttarget.logger.info(\n\t\t\t\t\t\t\t\t\t`✨`,\n\t\t\t\t\t\t\t\t\tstate.type,\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\t`computed default`,\n\t\t\t\t\t\t\t\t\tdef,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn def\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\tthrow e\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdef = state.default\n\t\t\t\ttarget.logger.info(`✨`, state.type, key, `using static default`, def)\n\t\t\t}\n\t\t\tconst cachedValue = writeToCache(target, state, def)\n\t\t\treturn cachedValue\n\t\t}\n\t}\n}\n","import type { ViewOf } from \"atom.io\"\n\nimport { readFromCache, writeToCache } from \"../caching\"\nimport { safeCompute } from \"../safe-compute\"\nimport type { ReadableState } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport function readOrComputeValue<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut?: undefined,\n): ViewOf<E | T>\nexport function readOrComputeValue<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut: `mut`,\n): E | T\nexport function readOrComputeValue<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut: `mut` | undefined,\n): E | T {\n\tif (target.valueMap.has(state.key)) {\n\t\treturn readFromCache(target, state, mut)\n\t}\n\ttarget.logger.info(`❔`, state.type, state.key, `value not found in cache`)\n\tconst { key } = state\n\tswitch (state.type) {\n\t\tcase `readonly_held_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\ttarget.logger.info(`🧮`, state.type, key, `computing value`)\n\t\t\treturn state.getFrom(target)\n\t\tcase `writable_pure_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `atom`:\n\t\t\treturn safeCompute(target, state)\n\t\tcase `mutable_atom`: {\n\t\t\tconst instance = new state.class()\n\t\t\ttarget.logger.info(`✨`, state.type, key, `created new instance`, instance)\n\t\t\tconst cachedValue = writeToCache(target, state, instance)\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 { Transceiver } from \"../mutable\"\nimport type {\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadonlyPureSelectorFamily,\n\tRegularAtomFamily,\n\tWritableFamily,\n\tWritablePureSelectorFamily,\n} from \"../state-types\"\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, E>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, K, E>,\n): RegularAtomFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, K, E>,\n): WritablePureSelectorFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, K, E>,\n): ReadonlyPureSelectorFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritableToken<T, K, E>,\n): WritableFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K, E>,\n): ReadableFamily<T, K, E>\n\nexport function getFamilyOfToken(\n\tstore: Store,\n\ttoken: ReadableToken<any, any, any>,\n): ReadableFamily<any, 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 type { ReadableToken, WritableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ReadableFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\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 const MUST_CREATE: unique symbol = Symbol(`MUST_CREATE`)\nexport const DO_NOT_CREATE: unique symbol = Symbol(`DO_NOT_CREATE`)\n\nexport function mintInStore<T, K extends Canonical, KK extends K, E>(\n\tmustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,\n\tstore: Store,\n\tfamily: ReadableFamily<T, K, E>,\n\tkey: KK,\n): WritableToken<T, KK, E>\nexport function mintInStore<T, K extends Canonical, KK extends K, E>(\n\tmustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,\n\tstore: Store,\n\tfamily: ReadableFamily<T, K, E>,\n\tkey: KK,\n): ReadableToken<T, KK, E>\nexport function mintInStore<T, K extends Canonical, KK extends K, E>(\n\tmustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,\n\tstore: Store,\n\tfamily: ReadableFamily<T, K, E>,\n\tkey: KK,\n): ReadableToken<T, KK, E> {\n\tconst stringKey = stringifyJson(key)\n\tconst molecule = store.molecules.get(stringKey)\n\n\tconst cannotCreate = !molecule && store.config.lifespan === `immortal`\n\n\tif (cannotCreate) {\n\t\tconst { type: familyType, key: familyKey } = family\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\tfamilyType,\n\t\t\t`\"${familyKey}\"`,\n\t\t)\n\t\tconst fullKey = `${familyKey}(${stringKey})`\n\t\tconst type = FAMILY_MEMBER_TOKEN_TYPES[familyType]\n\t\tconst stateToken: ReadableToken<T, KK, E> & { counterfeit: true } = {\n\t\t\tcounterfeit: true,\n\t\t\tkey: fullKey,\n\t\t\ttype,\n\t\t\tfamily: {\n\t\t\t\tkey: familyKey,\n\t\t\t\tsubKey: stringKey,\n\t\t\t},\n\t\t}\n\n\t\treturn stateToken\n\t}\n\n\tlet token: ReadableToken<T, KK, E>\n\tif (mustCreate === MUST_CREATE) {\n\t\tstore.logger.info(\n\t\t\t`👪`,\n\t\t\tfamily.type,\n\t\t\tfamily.key,\n\t\t\t`adds member`,\n\t\t\ttypeof key === `string` ? `\\`${key}\\`` : key,\n\t\t)\n\t\ttoken = family.create(key)\n\t\tif (molecule) {\n\t\t\tstore.moleculeData.set(stringKey, family.key)\n\t\t}\n\t} else {\n\t\tconst { type: familyType, key: familyKey } = family\n\t\tconst fullKey = `${familyKey}(${stringKey})`\n\t\tconst type = FAMILY_MEMBER_TOKEN_TYPES[familyType]\n\t\tconst stateToken: ReadableToken<T, KK, E> = {\n\t\t\tkey: fullKey,\n\t\t\ttype,\n\t\t\tfamily: {\n\t\t\t\tkey: familyKey,\n\t\t\t\tsubKey: stringKey,\n\t\t\t},\n\t\t}\n\n\t\treturn stateToken\n\t}\n\n\treturn token\n}\n","import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tStateCreationEvent,\n} 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 { newest } from \"../lineage\"\nimport type { ReadableFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { isChildStore, isRootStore } from \"../transaction\"\n\nexport function reduceReference<T, K extends Canonical, E>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<T, K, E>]\n): {\n\ttoken: ReadableToken<T, K, E>\n\tfamily: ReadableFamily<T, K, E> | undefined\n\tsubKey: NoInfer<K> | undefined\n\tisNew: boolean\n} {\n\tlet existingToken: ReadableToken<T, K, E> | undefined\n\tlet brandNewToken: ReadableToken<T, K, E> | undefined\n\tlet family: ReadableFamily<T, K, E> | undefined\n\tlet subKey: K | undefined\n\tlet token: ReadableToken<T, K, E>\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t\tif (`family` in token) {\n\t\t\tconst familyToken = getFamilyOfToken(store, token)\n\t\t\tfamily = withdraw(store, familyToken) as ReadableFamily<T, K, E>\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\tfamily,\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(MUST_CREATE, store, familyToken, subKey)\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 = withdraw(store, params[0])\n\t\tsubKey = params[1]\n\t\texistingToken = seekInStore(store, family, subKey)\n\t\tif (!existingToken) {\n\t\t\tbrandNewToken = mintInStore(MUST_CREATE, store, family, subKey)\n\t\t\ttoken = brandNewToken\n\t\t} else {\n\t\t\ttoken = existingToken\n\t\t}\n\t}\n\n\tconst isCounterfeit = `counterfeit` in token\n\tconst isNewlyCreated = Boolean(brandNewToken) && isCounterfeit === false\n\tif (isNewlyCreated && family) {\n\t\tlet subType: `readable` | `writable`\n\t\tswitch (token.type) {\n\t\t\tcase `readonly_pure_selector`:\n\t\t\tcase `readonly_held_selector`:\n\t\t\t\tsubType = `readable`\n\t\t\t\tbreak\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\tcase `writable_pure_selector`:\n\t\t\tcase `writable_held_selector`:\n\t\t\t\tsubType = `writable`\n\t\t\t\tbreak\n\t\t}\n\t\tconst stateCreationEvent: StateCreationEvent<any> = {\n\t\t\ttype: `state_creation`,\n\t\t\tsubType,\n\t\t\ttoken,\n\t\t\ttimestamp: Date.now(),\n\t\t}\n\t\tconst familySubject = family.subject as Subject<StateCreationEvent<any>>\n\t\tfamilySubject.next(stateCreationEvent)\n\t\tconst target = newest(store)\n\t\tif (token.family) {\n\t\t\tif (isRootStore(target)) {\n\t\t\t\tswitch (token.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(token)\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(token)\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(stateCreationEvent)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\ttoken,\n\t\tfamily,\n\t\tsubKey,\n\t\tisNew: Boolean(brandNewToken),\n\t}\n}\n","import type { ReadableFamilyToken, ReadableToken, ViewOf } 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, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n): E | T\n\nexport function getFromStore<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): ViewOf<E | T>\n\nexport function getFromStore<T, K extends Canonical, E>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<T, any, E>]\n): ViewOf<E | T>\n\nexport function getFromStore<T, K extends Canonical, E>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<T, any, E>]\n): ViewOf<E | T> {\n\tconst { token, family, subKey } = reduceReference(store, ...params)\n\n\tif (`counterfeit` in token && family && subKey) {\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 {\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 { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport type { ReadableState } from \"../state-types\"\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, Key> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K, E>,\n\tkey: Key,\n): RegularAtomToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K, E>,\n\tkey: Key,\n): AtomToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): WritablePureSelectorToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): SelectorToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K, E>,\n\tkey: Key,\n): WritableToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadableToken<T, Key, E> | undefined\n\nexport function seekInStore(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, any, any>,\n\tkey: Canonical,\n): ReadableToken<any, any, any> | undefined {\n\tconst subKey = stringifyJson(key)\n\tconst fullKey = `${token.key}(${subKey})`\n\tconst target = newest(store)\n\tlet state: ReadableState<any, 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 { DO_NOT_CREATE, 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, Key>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: RegularAtomFamilyToken<T, K, E>,\n\tkey: Key,\n): RegularAtomToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: AtomFamilyToken<T, K, E>,\n\tkey: Key,\n): AtomToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: WritablePureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): WritablePureSelectorToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: ReadonlyPureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: SelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): SelectorToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: WritableFamilyToken<T, K, E>,\n\tkey: Key,\n): WritableToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadableToken<T, Key, E>\n\nexport function findInStore(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<any, any, any>,\n\tkey: Canonical,\n): ReadableToken<any, any, any> {\n\tconst family = withdraw(store, familyToken)\n\tconst existingStateToken = seekInStore(store, familyToken, key)\n\tif (existingStateToken) {\n\t\treturn existingStateToken\n\t}\n\tconst newStateToken = mintInStore(DO_NOT_CREATE, store, family, key)\n\treturn newStateToken\n}\n","import type {\n\tFamilyMetadata,\n\tfindState,\n\tgetState,\n\tReadonlyPureSelectorFamilyOptions,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorOptions,\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 { getFromStore } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { createReadonlyPureSelector } from \"../selector\"\nimport type { ReadonlyPureSelectorFamily } from \"../state-types\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\nimport { findInStore } from \"./find-in-store\"\n\nexport function createReadonlyPureSelectorFamily<T, K extends Canonical, E>(\n\tstore: RootStore,\n\toptions: ReadonlyPureSelectorFamilyOptions<T, K, E>,\n\tinternalRoles?: string[],\n): ReadonlyPureSelectorFamilyToken<T, K, E> {\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, E>\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, K, E>>\n\t>()\n\n\tconst create = <Key extends K>(\n\t\tkey: Key,\n\t): ReadonlyPureSelectorToken<T, Key, E> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata<Key> = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\t\tconst individualOptions: ReadonlyPureSelectorOptions<T, E> = {\n\t\t\tkey: fullKey,\n\t\t\tget: options.get(key),\n\t\t}\n\t\tif (options.catch) {\n\t\t\tindividualOptions.catch = options.catch\n\t\t}\n\n\t\treturn createReadonlyPureSelector<T, Key, E>(\n\t\t\ttarget,\n\t\t\tindividualOptions,\n\t\t\tfamily,\n\t\t)\n\t}\n\n\tconst readonlySelectorFamily: ReadonlyPureSelectorFamily<T, K, E> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => 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}\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 { createRegularAtom } from \"../atom\"\nimport { isFn } from \"../is-fn\"\nimport { newest } from \"../lineage\"\nimport type { RegularAtomFamily } from \"../state-types\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\n\nexport function createRegularAtomFamily<T, K extends Canonical, E>(\n\tstore: RootStore,\n\toptions: RegularAtomFamilyOptions<T, K, E>,\n\tinternalRoles?: string[],\n): RegularAtomFamilyToken<T, K, E> {\n\tconst familyToken: RegularAtomFamilyToken<T, K, E> = {\n\t\tkey: options.key,\n\t\ttype: `atom_family`,\n\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`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, K, E>>>()\n\n\tconst create = <Key extends K>(key: Key): RegularAtomToken<T, Key, E> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata<Key> = { 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, E> = {\n\t\t\tkey: fullKey,\n\t\t\tdefault: isFn(def) ? () => def(key) : def,\n\t\t}\n\t\tif (options.effects) {\n\t\t\tindividualOptions.effects = options.effects(key)\n\t\t}\n\t\tif (options.catch) {\n\t\t\tindividualOptions.catch = options.catch\n\t\t}\n\n\t\treturn createRegularAtom(target, individualOptions, family)\n\t}\n\n\tconst atomFamily: RegularAtomFamily<T, K, E> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tdefault: options.default,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => createRegularAtomFamily(s, options),\n\t\tinternalRoles,\n\t}\n\n\tstore.families.set(options.key, atomFamily)\n\tif (isFn(options.default) === 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 { newest } from \"../lineage\"\nimport { createReadonlyHeldSelector } from \"../selector\"\nimport type { ReadonlyHeldSelectorFamily } from \"../state-types\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\n\nexport function createReadonlyHeldSelectorFamily<\n\tT extends object,\n\tK extends Canonical,\n>(\n\tstore: RootStore,\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 create = (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\treturn 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\t}\n\n\tconst readonlySelectorFamily: ReadonlyHeldSelectorFamily<T, K> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => createReadonlyHeldSelectorFamily(s, options),\n\t\tdefault: options.const,\n\t}\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 { newest } from \"../lineage\"\nimport { createWritableHeldSelector } from \"../selector\"\nimport type { WritableHeldSelectorFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\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 create = (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\treturn 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\t}\n\n\tconst selectorFamily: WritableHeldSelectorFamily<T, K> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => createWritableHeldSelectorFamily(s, options),\n\t\tdefault: options.const,\n\t}\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\tWritablePureSelectorOptions,\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 { getFromStore } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { createWritablePureSelector } from \"../selector\"\nimport type { WritablePureSelectorFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\nimport { findInStore } from \"./find-in-store\"\n\nexport function createWritablePureSelectorFamily<T, K extends Canonical, E>(\n\tstore: Store,\n\toptions: WritablePureSelectorFamilyOptions<T, K, E>,\n\tinternalRoles?: string[],\n): WritablePureSelectorFamilyToken<T, K, E> {\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, E>\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, K, E>>\n\t>()\n\n\tconst create = <Key extends K>(\n\t\tkey: Key,\n\t): WritablePureSelectorToken<T, Key, E> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata<Key> = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\t\tconst individualOptions: WritablePureSelectorOptions<T, E> = {\n\t\t\tkey: fullKey,\n\t\t\tget: options.get(key),\n\t\t\tset: options.set(key),\n\t\t}\n\t\tif (options.catch) {\n\t\t\tindividualOptions.catch = options.catch\n\t\t}\n\n\t\treturn createWritablePureSelector<T, Key, E>(\n\t\t\ttarget,\n\t\t\tindividualOptions,\n\t\t\tfamily,\n\t\t)\n\t}\n\n\tconst selectorFamily: WritablePureSelectorFamily<T, K, E> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => 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}\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 { RootStore } from \"../transaction\"\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: RootStore,\n\toptions: WritableHeldSelectorFamilyOptions<T, K>,\n): WritableHeldSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T extends object, K extends Canonical>(\n\tstore: RootStore,\n\toptions: ReadonlyHeldSelectorFamilyOptions<T, K>,\n): ReadonlyHeldSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T, K extends Canonical, E>(\n\tstore: RootStore,\n\toptions: WritablePureSelectorFamilyOptions<T, K, E>,\n): WritablePureSelectorFamilyToken<T, K, E>\nexport function createSelectorFamily<T, K extends Canonical, E>(\n\tstore: RootStore,\n\toptions: ReadonlyPureSelectorFamilyOptions<T, K, E>,\n): ReadonlyPureSelectorFamilyToken<T, K, E>\nexport function createSelectorFamily(\n\tstore: RootStore,\n\toptions:\n\t\t| ReadonlyHeldSelectorFamilyOptions<any, any>\n\t\t| ReadonlyPureSelectorFamilyOptions<any, any, any>\n\t\t| WritableHeldSelectorFamilyOptions<any, any>\n\t\t| WritablePureSelectorFamilyOptions<any, any, any>,\n): SelectorFamilyToken<any, 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 { 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(\n\tstore: Store,\n\ttoken: ReadableToken<any, any, any>,\n): void\n\nexport function disposeFromStore<K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, K, any>,\n\tkey: NoInfer<K>,\n): void\n\nexport function disposeFromStore<K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<any, K, any>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<any, any, any>]\n): void\n\nexport function disposeFromStore(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<any, any, any>, key: Canonical]\n\t\t| [token: ReadableToken<any, any, any>]\n): void {\n\tlet token: ReadableToken<any, any, 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 { AtomUpdateEvent, ReadableToken, StateCreationEvent } 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<\n\tR extends ReadableToken<any, any> = ReadableToken<any, any>,\n> = {\n\topen: true\n\ttoken: R\n\tdone: Set<string>\n\tprev: Map<string, any>\n\ttimestamp: number\n\tsubEvents: (AtomUpdateEvent<any> | StateCreationEvent<any>)[]\n}\n\nexport function openOperation(\n\tstore: Store,\n\ttoken: ReadableToken<any, any, 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\tsubEvents: [],\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 {\n\tAtomUpdateEvent,\n\tStateCreationEvent,\n\tStateUpdate,\n\tTimelineEvent,\n} from \"atom.io\"\n\nimport { hasRole } from \"../atom\"\nimport { readOrComputeValue } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport { isTransceiver } from \"../mutable\"\nimport type { OpenOperation } from \"../operation\"\nimport type { MutableAtom, WritableFamily, WritableState } from \"../state-types\"\nimport { deposit, type Store } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { isChildStore, isRootStore } from \"../transaction\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\n\nexport function dispatchOrDeferStateUpdate<T, E>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tstate: WritableState<T, E>,\n\t{ oldValue, newValue }: ProtoUpdate<E | T>,\n\tstateIsNewlyCreated: boolean,\n\tfamily?: WritableFamily<T, any, E>,\n): void {\n\tconst token = deposit(state)\n\tif (stateIsNewlyCreated && family) {\n\t\tstate.subject.next({ newValue })\n\t\tconst stateCreationEvent: StateCreationEvent<any> & TimelineEvent<any> = {\n\t\t\tcheckpoint: true,\n\t\t\ttype: `state_creation`,\n\t\t\tsubType: `writable`,\n\t\t\ttoken,\n\t\t\ttimestamp: Date.now(),\n\t\t\tvalue: newValue,\n\t\t}\n\t\ttarget.operation.subEvents.push(stateCreationEvent)\n\t\tconst familySubject = family.subject as Subject<StateCreationEvent<any>>\n\t\tfamilySubject.next(stateCreationEvent)\n\t\tconst innerTarget = newest(target)\n\t\tif (token.family) {\n\t\t\tif (isRootStore(innerTarget)) {\n\t\t\t\tswitch (token.type) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\ttarget.on.atomCreation.next(token)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\t\tcase `writable_held_selector`:\n\t\t\t\t\t\ttarget.on.selectorCreation.next(token)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisChildStore(innerTarget) &&\n\t\t\t\tinnerTarget.on.transactionApplying.state === null\n\t\t\t) {\n\t\t\t\tinnerTarget.transactionMeta.update.subEvents.push(stateCreationEvent)\n\t\t\t}\n\t\t}\n\t\treturn /* bailing early here to avoid redundant update */\n\t}\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.keys(),\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.keys(),\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\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<any> = {\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<Transceiver<any, any, any>, never>(\n\t\t\t\ttarget,\n\t\t\t\tmutable,\n\t\t\t\t`mut`,\n\t\t\t)\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 { writeToCache } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport type { OpenOperation } from \"../operation\"\nimport { markDone } from \"../operation\"\nimport type { Atom } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\n\nexport const setAtom = <T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tatom: Atom<T, any>,\n\tnext: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n): ProtoUpdate<T> => {\n\tconst oldValue = readOrComputeValue(target, atom, `mut`)\n\tlet newValue = become(next, oldValue)\n\ttarget.logger.info(`⭐`, `atom`, atom.key, `setting value`, newValue)\n\tnewValue = writeToCache(target, atom, newValue)\n\tmarkDone(target, atom.key)\n\tevictDownstreamFromAtom(target, atom)\n\treturn { oldValue, newValue }\n}\n","import { isFn } from \"../is-fn\"\nimport type { OpenOperation } from \"../operation\"\nimport { safeCompute } from \"../safe-compute\"\nimport { traceRootSelectorAtoms } from \"../selector\"\nimport type { Atom, WritableState } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { dispatchOrDeferStateUpdate } from \"./dispatch-state-update\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\nimport { setAtom } from \"./set-atom\"\n\nfunction resetAtom<T, E>(\n\ttarget: Store & { operation: OpenOperation },\n\tatom: Atom<T, E>,\n): ProtoUpdate<E | 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: E | T\n\t\t\tif (isFn(atom.default)) def = safeCompute(target, atom)\n\t\t\telse def = atom.default\n\t\t\treturn setAtom<E | T>(target, atom, def)\n\t\t}\n\t}\n}\n\nexport function resetAtomOrSelector<T, E>(\n\ttarget: Store & { operation: OpenOperation },\n\tstate: WritableState<T, E>,\n): ProtoUpdate<E | T> {\n\tlet protoUpdate: ProtoUpdate<E | 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_held_selector`:\n\t\t\t{\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 value = state.getFrom(target)\n\t\t\t\tprotoUpdate = { oldValue: value, newValue: value }\n\t\t\t}\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\t\t{\n\t\t\t\tconst oldValue = safeCompute(target, state)\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 = safeCompute(target, state)\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 { Setter, 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, TT extends T>(\n\tstore: Store,\n\ttoken: WritableToken<T, any, any>,\n\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n): void\n\nexport function setIntoStore<T, TT extends T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n): void\n\nexport function setIntoStore<T, TT extends T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, K, any>,\n\t\t\t\tkey: NoInfer<K>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T, any, any>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n): void\n\nexport function setIntoStore<T, TT extends T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, K, any>,\n\t\t\t\tkey: NoInfer<K>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T, any, any>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n): void {\n\toperateOnStore(OWN_OP, store, ...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(\n\tstore: Store,\n\ttoken: WritableToken<any, any, any>,\n): void\n\nexport function resetInStore<K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<any, K, any>,\n\tkey: NoInfer<K>,\n): void\n\nexport function resetInStore<T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]\n\t\t| [token: WritableToken<T, any, any>]\n): void\n\nexport function resetInStore<T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]\n\t\t| [token: WritableToken<T, any, any>]\n): void {\n\tconst subParams = [...params, RESET_STATE] as const\n\tsetIntoStore(store, ...subParams)\n}\n","import { writeToCache } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state\"\nimport { markDone, type OpenOperation } from \"../operation\"\nimport type { WritableSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\n\nexport function setSelector<T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tselector: WritableSelector<T, any>,\n\tnext: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n): ProtoUpdate<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 = readOrComputeValue(target, selector, `mut`)\n\t\t\tnewValue = become(next, oldValue)\n\t\t\tnewValue = writeToCache(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 { OpenOperation } from \"../operation\"\nimport type { WritableState } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport type { ProtoUpdate } from \"./operate-on-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, any>,\n\tvalue: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n): ProtoUpdate<T> => {\n\tlet protoUpdate: ProtoUpdate<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 { Setter, 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 { WritableFamily } from \"../state-types\"\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 type ProtoUpdate<T> = { oldValue: T; newValue: T }\n\nexport const OWN_OP: unique symbol = Symbol(`OWN_OP`)\nexport const JOIN_OP: unique symbol = Symbol(`JOIN_OP`)\n\nexport function operateOnStore<T, TT extends T, K extends Canonical, E>(\n\topMode: typeof JOIN_OP | typeof OWN_OP,\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, K, E>,\n\t\t\t\tkey: NoInfer<K>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T, any, E>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n): void {\n\tlet existingToken: WritableToken<T, K, E> | undefined\n\tlet brandNewToken: WritableToken<T, K, E> | undefined\n\tlet token: WritableToken<T, K, E>\n\tlet family: WritableFamily<T, K, E> | undefined\n\tlet key: K | null\n\tlet value: Setter<TT> | TT | typeof RESET_STATE\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\ttoken = brandNewToken = mintInStore(MUST_CREATE, store, family, key)\n\t\t\t} else {\n\t\t\t\ttoken = existingToken\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfamily = withdraw(store, 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\ttoken = brandNewToken = mintInStore(MUST_CREATE, store, family, key)\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(opMode, store, 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: ProtoUpdate<E | 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\n\tconst isNewlyCreated = Boolean(brandNewToken)\n\tdispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated, family)\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 { isAtomKey } from \"../keys\"\nimport type { Atom } from \"../state-types\"\nimport type { Store } from \"../store\"\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<any, any>> {\n\tconst dependencies = getSelectorDependencyKeys(store, selectorKey)\n\n\tconst roots = new Map<string, Atom<unknown, 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, 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, any, 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, any>, Canonical]\n\t\t\t\t| [ReadableToken<any, any, any>]\n\t\t) => {\n\t\t\tconst target = newest(store)\n\t\t\tconst { token, family, subKey } = reduceReference(store, ...params)\n\t\t\tlet dependencyValue: unknown\n\t\t\tif (`counterfeit` in token && family && subKey) {\n\t\t\t\tdependencyValue = getFallback(store, token, family, 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>(\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: NoInfer<K>,\n\t\t\t\t\t\tvalue: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n\t\t\t\t ]\n\t\t\t\t| [\n\t\t\t\t\t\ttoken: WritableToken<T>,\n\t\t\t\t\t\tvalue: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n\t\t\t\t ]\n\t\t) => {\n\t\t\tconst target = newest(store)\n\t\t\toperateOnStore(JOIN_OP, target, ...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 { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { ReadonlyHeldSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\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\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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\tstore.logger.info(`✨`, type, key, `=`, 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: RootStore) => createReadonlyHeldSelector(s, options, family),\n\t}\n\tif (family) readonlySelector.family = family\n\n\ttarget.readonlySelectors.set(key, readonlySelector)\n\tconst token: ReadonlyHeldSelectorToken<T> = { key, type }\n\tif (family) token.family = family\n\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyPureSelectorOptions,\n\tReadonlyPureSelectorToken,\n\tStateUpdate,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { ReadonlyPureSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function createReadonlyPureSelector<T, K extends Canonical, E>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorOptions<T, E>,\n\tfamily: FamilyMetadata<K> | undefined,\n): ReadonlyPureSelectorToken<T, K, E> {\n\tconst target = newest(store)\n\tconst subject = new Subject<StateUpdate<E | T>>()\n\tconst covered = new Set<string>()\n\tconst key = options.key\n\tconst type = `readonly_pure_selector` as const\n\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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, E> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tgetFrom,\n\t\tinstall: (s: RootStore) => createReadonlyPureSelector(s, options, family),\n\t}\n\tif (family) readonlySelector.family = family\n\n\ttarget.readonlySelectors.set(key, readonlySelector)\n\n\tconst token: ReadonlyPureSelectorToken<T> = { key, type }\n\tif (family) token.family = family\n\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tWritableHeldSelectorOptions,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\n\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { WritableHeldSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\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\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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: RootStore) => createWritableHeldSelector(s, options, family),\n\t}\n\tif (family) mySelector.family = family\n\n\ttarget.writableSelectors.set(key, mySelector)\n\n\tconst token: WritableHeldSelectorToken<T> = { key, type }\n\tif (family) token.family = family\n\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tStateUpdate,\n\tWritablePureSelectorOptions,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { WritablePureSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function createWritablePureSelector<T, K extends Canonical, E>(\n\tstore: Store,\n\toptions: WritablePureSelectorOptions<T, E>,\n\tfamily: FamilyMetadata<K> | undefined,\n): WritablePureSelectorToken<T, K, E> {\n\tconst target = newest(store)\n\tconst subject = new Subject<StateUpdate<E | T>>()\n\tconst covered = new Set<string>()\n\tconst key = options.key\n\tconst type = `writable_pure_selector` as const\n\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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): E | 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, E> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tgetFrom,\n\t\tsetSelf,\n\t\tinstall: (s: RootStore) => createWritablePureSelector(s, options, family),\n\t}\n\tif (family) mySelector.family = family\n\n\ttarget.writableSelectors.set(key, mySelector)\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, E>(\n\tstore: Store,\n\toptions: WritablePureSelectorOptions<T, E>,\n): WritablePureSelectorToken<T, any, E>\nexport function createStandaloneSelector<T, E>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorOptions<T, E>,\n): ReadonlyPureSelectorToken<T, any, E>\nexport function createStandaloneSelector(\n\tstore: Store,\n\toptions:\n\t\t| ReadonlyHeldSelectorOptions<any>\n\t\t| ReadonlyPureSelectorOptions<any, any>\n\t\t| WritableHeldSelectorOptions<any>\n\t\t| WritablePureSelectorOptions<any, any>,\n):\n\t| ReadonlyHeldSelectorToken<any>\n\t| ReadonlyPureSelectorToken<any, any, any>\n\t| WritableHeldSelectorToken<any>\n\t| WritablePureSelectorToken<any, any, 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 { newest } from \"../lineage\"\nimport { type Store, withdraw } from \"../store\"\nimport { isChildStore } from \"../transaction\"\n\nexport function disposeSelector(\n\tstore: Store,\n\tselectorToken: SelectorToken<unknown, any, any>,\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, 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 { newest } from \"../lineage\"\nimport type { ReadableState } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport const recallState = <T, E>(\n\tstore: Store,\n\tstate: ReadableState<T, E>,\n): 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 { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport type { Atom, Selector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { recallState } from \"./recall-state\"\n\nexport const subscribeToRootDependency = (\n\ttarget: Store,\n\tselector: Selector<any, any>,\n\tatom: Atom<any, 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","import type { ReadableToken, StateUpdate, UpdateHandler } from \"atom.io\"\n\nimport { hasRole } from \"../atom\"\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, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n\tkey: string,\n\thandleUpdate: UpdateHandler<E | T>,\n): () => void {\n\tfunction safelyHandleUpdate(update: StateUpdate<any>): void {\n\t\tif (store.operation.open) {\n\t\t\tif (\n\t\t\t\tstate?.type === `atom` &&\n\t\t\t\thasRole(state, `tracker:signal`) &&\n\t\t\t\t`*` + store.operation.token.key === token.key &&\n\t\t\t\t`inboundTracker` in handleUpdate\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\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<E | 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 { 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 { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Fn } from \"../utility-types\"\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 {\n\tFamilyMetadata,\n\tMutableAtomToken,\n\tRegularAtomToken,\n\tStateUpdate,\n} from \"atom.io\"\n\nimport { createRegularAtom } from \"../atom\"\nimport { getFromStore } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport { setIntoStore } from \"../set-state\"\nimport { JOIN_OP, operateOnStore } from \"../set-state/operate-on-store\"\nimport type { Store } from \"../store\"\nimport { subscribeToState, subscribeToTimeline } from \"../subscribe\"\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<\n\t\t\tSignalFrom<T> | null,\n\t\t\tany,\n\t\t\tnever\n\t\t>(\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-from-core:${storeName}:${storeStatus}:${stateKey}`\n\t\tconst trackerCapturesOutboundSignal = (update: SignalFrom<T>) => {\n\t\t\toperateOnStore(JOIN_OP, 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 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-to-core:${storeName}:${storeStatus}:${stateKey}`\n\t\tsubscribeToState(\n\t\t\ttarget,\n\t\t\tlatestSignalState,\n\t\t\tsubscriptionKey,\n\t\t\tObject.assign(\n\t\t\t\tfunction trackerCapturesInboundSignal({\n\t\t\t\t\tnewValue,\n\t\t\t\t\toldValue,\n\t\t\t\t}: StateUpdate<SignalFrom<T> | null>) {\n\t\t\t\t\tconst timelineId = target.timelineTopics.getRelatedKey(\n\t\t\t\t\t\tlatestSignalState.key,\n\t\t\t\t\t)\n\n\t\t\t\t\tif (timelineId && target.timelines.get(timelineId)?.timeTraveling) {\n\t\t\t\t\t\tconst unsubscribe = subscribeToTimeline(\n\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t{ key: timelineId, type: `timeline` },\n\t\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\t\tfunction trackerWaitsForTimeTravelToFinish(update) {\n\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\tsetIntoStore(target, mutableState, (transceiver) => {\n\t\t\t\t\t\t\t\t\tif (update === `redo` && newValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.do(newValue)\n\t\t\t\t\t\t\t\t\t} else if (update === `undo` && oldValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.undo(oldValue)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn transceiver\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// const mutable = getFromStore(target, mutableState)\n\t\t\t\t\t// const updateNumber = mutable.getUpdateNumber(newValue)\n\t\t\t\t\t// const eventOffset = updateNumber - mutable.cacheUpdateNumber\n\t\t\t\t\t// if (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\t// } else {\n\t\t\t\t\t// \tconst expected = mutable.cacheUpdateNumber + 1\n\t\t\t\t\t// \ttarget.logger.info(\n\t\t\t\t\t// \t\t`❌`,\n\t\t\t\t\t// \t\t`mutable_atom`,\n\t\t\t\t\t// \t\tmutableState.key,\n\t\t\t\t\t// \t\t`could not be updated. Expected update number`,\n\t\t\t\t\t// \t\texpected,\n\t\t\t\t\t// \t\t`but got`,\n\t\t\t\t\t// \t\tupdateNumber,\n\t\t\t\t\t// \t)\n\t\t\t\t\t// }\n\t\t\t\t},\n\t\t\t\t{ inboundTracker: true },\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 { newest } from \"../lineage\"\nimport { createStandaloneSelector } from \"../selector\"\nimport { resetInStore, setIntoStore } from \"../set-state\"\nimport type { MutableAtom } from \"../state-types\"\nimport { deposit, type Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport type { RootStore } from \"../transaction\"\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: RootStore) => {\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 { createRegularAtomFamily } from \"../families\"\nimport type { MutableAtomFamily, RegularAtomFamily } from \"../state-types\"\nimport { withdraw } from \"../store\"\nimport type { RootStore } from \"../transaction\"\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: RootStore) {\n\t\tconst latestSignalAtoms = createRegularAtomFamily<\n\t\t\tSignalFrom<T> | null,\n\t\t\tK,\n\t\t\tnever\n\t\t>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `*${mutableAtoms.key}`,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\t[`mutable`, `updates`],\n\t\t)\n\t\tthis.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 } from \"../families\"\nimport { newest } from \"../lineage\"\nimport { createMutableAtom } from \"../mutable\"\nimport type { MutableAtomFamily } from \"../state-types\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\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: RootStore,\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 create = (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\treturn createMutableAtom(target, individualOptions, family)\n\t}\n\n\tconst atomFamily: MutableAtomFamily<T, K> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tclass: options.class,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => createMutableAtomFamily(s, options),\n\t\tinternalRoles,\n\t}\n\n\tstore.families.set(options.key, atomFamily)\n\n\tcreateWritablePureSelectorFamily<AsJSON<T>, K, never>(\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 { newest } from \"../lineage\"\nimport type { WritablePureSelectorFamily } from \"../state-types\"\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, never> => {\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\tnever\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 { newest } from \"../lineage\"\nimport type { RegularAtomFamily } from \"../state-types\"\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): RegularAtomFamily<SignalFrom<T>, K, never> => {\n\tconst target = newest(store)\n\tconst key = `*${mutableAtomFamily.key}`\n\tconst updateFamily = target.families.get(key) as RegularAtomFamily<\n\t\tSignalFrom<T>,\n\t\tK,\n\t\tnever\n\t>\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\t// cacheUpdateNumber: number\n\t// getUpdateNumber: (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 { Future } from \"./future\"\nimport { Tracker, type Transceiver } from \"./mutable\"\nimport { closeOperation, openOperation } from \"./operation\"\nimport {\n\tevictDownstreamFromAtom,\n\tevictDownstreamFromSelector,\n} from \"./set-state/evict-downstream\"\nimport type { ReadableState } from \"./state-types\"\nimport type { Store } from \"./store\"\nimport { isChildStore } from \"./transaction\"\n\nexport function writeToCache<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tvalue: E | T,\n): E | T\nexport function writeToCache<T extends Promise<any>, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tvalue: T,\n): Future<Awaited<E | T>>\nexport function writeToCache<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tvalue: E | T,\n): E | Future<E | 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\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 definition, 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.type, key, `rejected:`, thrown)\n\t\t\t})\n\t\treturn future\n\t}\n\ttarget.logger.info(`📝`, state.type, state.key, `writing to cache`, value)\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, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut: `mut` | undefined,\n): E | T {\n\ttarget.logger.info(`📖`, state.type, state.key, `reading cached value`)\n\tlet value = target.valueMap.get(state.key) as E | 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 { evictCachedValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Atom } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport function evictDownstreamFromAtom(\n\tstore: Store,\n\tatom: Atom<any, any>,\n): 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 {\n\tFamilyMetadata,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport { resetInStore, setIntoStore } from \"../set-state\"\nimport type { RegularAtom } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport type { RootStore } from \"../transaction\"\nimport type { InternalRole } from \"./has-role\"\n\nexport function createRegularAtom<T, K extends Canonical, E>(\n\tstore: Store,\n\toptions: RegularAtomOptions<T, E>,\n\tfamily: FamilyMetadata<K> | undefined,\n\tinternalRoles?: InternalRole[],\n): RegularAtomToken<T, K, E> {\n\tconst type = `atom`\n\tconst { key } = options\n\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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) as RegularAtomToken<T, K, E>\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: RegularAtom<T, E> = {\n\t\t...options,\n\t\ttype,\n\t\tinstall: (s: RootStore) => {\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) as RegularAtomToken<T, K, E>\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 { Atom } from \"../state-types\"\n\nexport const INTERNAL_ROLES = [`tracker:signal`] as const\nexport type InternalRole = (typeof INTERNAL_ROLES)[number]\n\nexport function hasRole(atom: Atom<any, 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","import type { AtomDisposalEvent, AtomToken, StateLifecycleEvent } from \"atom.io\"\n\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { newest } from \"../lineage\"\nimport { getUpdateToken } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { isChildStore } from \"../transaction\"\nimport { hasRole } from \"./has-role\"\n\nexport function disposeAtom(\n\tstore: Store,\n\tatomToken: AtomToken<any, any, any>,\n): 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, any, any>>\n\t\t>\n\n\t\tconst disposalEvent: AtomDisposalEvent<AtomToken<any, any, 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(disposalEvent)\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\t\t\tconst isTracker = hasRole(atom, `tracker:signal`)\n\t\t\tif (!updateAlreadyCaptured && !isTracker) {\n\t\t\t\ttarget.transactionMeta.update.subEvents.push(disposalEvent)\n\t\t\t}\n\t\t} else {\n\t\t\tstore.on.atomDisposal.next(atomToken)\n\t\t}\n\t}\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 type { RootStore } from \"./transaction\"\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: RootStore,\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 { Json } 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 { createMutableAtomFamily, getJsonFamily, getJsonToken } from \"../mutable\"\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport type { RootStore } from \"../transaction\"\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 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: RootStore = 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) =>\n\t\t\tget(relatedKeysAtoms, key) as SetRTX<AType> | SetRTX<BType>\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\tconst [x, y] = [a, b].sort()\n\t\t\tconst compositeKey = `${x}:${y}`\n\t\t\tthis.store.moleculeJoins.delete(compositeKey)\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 [x, y] = [newRelationB, previousOwner].sort()\n\t\t\t\t\t\t\t\tconst compositeKey = `${x}:${y}`\n\t\t\t\t\t\t\t\tstore.moleculeJoins.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(`\"${a}\"`, options.key)\n\t\t\t\tthis.store.moleculeJoins.set(`\"${b}\"`, options.key)\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, never>(\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) => {},\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 [x, y] = args.sort()\n\t\t\t\t\tconst compositeKey = `${x}:${y}`\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\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, never>(\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, never>(\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<\n\t\t\t\t[string, ViewOf<Content>] | null,\n\t\t\t\tstring,\n\t\t\t\tnever\n\t\t\t>(\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<\n\t\t\t\t[string, ViewOf<Content>][],\n\t\t\t\tstring,\n\t\t\t\tnever\n\t\t\t>(\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 { RootStore } from \"../transaction\"\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: RootStore,\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 { eldest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } 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\tconst root = eldest(store)\n\t\tmyJoin = new Join(rootJoin.options, rootJoin.defaultContent, root)\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 { RootStore } from \"../transaction\"\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: RootStore,\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 { RootStore } from \"../transaction\"\nimport { getJoin } from \"./get-join\"\n\nexport function getInternalRelationsFromStore(\n\ttoken: JoinToken<any, any, any, any, any, any>,\n\tstore: RootStore,\n): MutableAtomFamilyToken<SetRTX<string>, string> {\n\tconst myJoin = getJoin(token, store)\n\tconst family = myJoin.core.relatedKeysAtoms\n\treturn family\n}\n","import type { primitive } from \"atom.io/json\"\n\nimport type { Flat } from \"./utility-types\"\n\nexport type IndexOf<\n\tT extends readonly unknown[],\n\tE,\n\tA extends unknown[] = [],\n> = T extends readonly [infer Head, ...infer Tail]\n\t? (<U>() => U extends Head ? 1 : 2) extends <U>() => U extends E ? 1 : 2\n\t\t? A[`length`]\n\t\t: IndexOf<Tail, E, [...A, unknown]>\n\t: never\n\nexport type Flip<T extends Record<string, number | string>> = {\n\t[K in keyof T as T[K]]: K\n}\n\nexport type TwoWay<T extends Record<string, number | string>> = Flip<T> & T\n\nexport type Enumeration<T extends readonly string[]> = Flat<\n\tTwoWay<{\n\t\t[K in T[number]]: IndexOf<T, K>\n\t}>\n>\n\nexport function enumeration<T extends readonly string[]>(\n\tvalues: T,\n): Enumeration<T> {\n\tconst result: Record<any, any> = {}\n\tlet i = 0\n\tfor (const value of values) {\n\t\tresult[value] = i\n\t\tresult[i] = value\n\t\t++i\n\t}\n\treturn result as Enumeration<T>\n}\n\nconst BOOL = `\\u0001`\nconst NULL = `\\u0002`\nconst STRING = `\\u0003`\nconst NUMBER = `\\u0004`\nexport const packValue = (value: primitive): string => {\n\tconst type = typeof value as `boolean` | `number` | `object` | `string`\n\tswitch (type) {\n\t\tcase `string`:\n\t\t\treturn STRING + value\n\t\tcase `number`:\n\t\t\treturn NUMBER + value\n\t\tcase `boolean`:\n\t\t\treturn BOOL + +(value as boolean)\n\t\tcase `object`:\n\t\t\treturn NULL\n\t}\n}\nexport const unpackValue = (value: string): primitive => {\n\tconst type = value[0] as `\\u0001` | `\\u0002` | `\\u0003` | `\\u0004`\n\tswitch (type) {\n\t\tcase STRING:\n\t\t\treturn value.slice(1)\n\t\tcase NUMBER:\n\t\t\treturn +value.slice(1)\n\t\tcase BOOL:\n\t\t\treturn value.slice(1) === `1`\n\t\tcase NULL:\n\t\t\treturn null\n\t}\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tAtomUpdateEvent,\n\tStateCreationEvent,\n\tStateDisposalEvent,\n\tStateUpdate,\n\tTimelineEvent,\n\tTimelineManageable,\n\tTimelineOptions,\n\tTimelineSelectorUpdateEvent,\n\tTimelineToken,\n\tTransactionOutcomeEvent,\n\tTransactionSubEvent,\n\tTransactionToken,\n\tWritablePureSelectorToken,\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 type { RootStore } from \"../transaction\"\nimport { isChildStore } from \"../transaction\"\n\nexport type Timeline<ManagedAtom extends TimelineManageable> = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineEvent<ManagedAtom>[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: RootStore) => void\n\tsubject: Subject<TimelineEvent<ManagedAtom> | `redo` | `undo`>\n\tsubscriptions: Map<string, () => void>\n}\n\nexport function createTimeline<ManagedAtom extends TimelineManageable>(\n\tstore: RootStore,\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\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\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<any, any, any> = 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, 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, any, 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\tbuildSelectorUpdate(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\ttl,\n\t\t\t\t\t\t\tatomToken,\n\t\t\t\t\t\t\tupdate,\n\t\t\t\t\t\t\tcurrentSelectorToken,\n\t\t\t\t\t\t\tcurrentSelectorTime,\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\n\t\t\t\t\t\tconst atomUpdate: AtomUpdateEvent<any> & TimelineEvent<any> = {\n\t\t\t\t\t\t\tcheckpoint: true,\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\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\taddToHistory(tl, atomUpdate)\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, 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\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: TimelineEvent<any> &\n\t\t\t\t\t\tTransactionOutcomeEvent<TransactionToken<any>> = {\n\t\t\t\t\t\tcheckpoint: true,\n\t\t\t\t\t\t...transactionUpdate,\n\t\t\t\t\t\tsubEvents: subEventsFiltered,\n\t\t\t\t\t}\n\n\t\t\t\t\taddToHistory(tl, timelineTransactionUpdate)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n}\n\nfunction buildSelectorUpdate(\n\tstore: Store,\n\ttl: Timeline<any>,\n\tatomToken: AtomToken<any, any, any>,\n\teventOrUpdate: StateCreationEvent<any> | StateUpdate<any>,\n\tcurrentSelectorToken: WritablePureSelectorToken<any>,\n\tcurrentSelectorTime: number,\n) {\n\tlet latestUpdate: TimelineEvent<any> | undefined = tl.history.at(-1)\n\tif (currentSelectorTime !== tl.selectorTime) {\n\t\tconst selectorUpdate: TimelineEvent<any> & TimelineSelectorUpdateEvent<any> =\n\t\t\t(latestUpdate = {\n\t\t\t\tcheckpoint: true,\n\t\t\t\ttype: `selector_update`,\n\t\t\t\ttimestamp: currentSelectorTime,\n\t\t\t\ttoken: currentSelectorToken,\n\t\t\t\tsubEvents: [],\n\t\t\t})\n\t\tif (`type` in eventOrUpdate) {\n\t\t\tlatestUpdate.subEvents.push(eventOrUpdate)\n\t\t} else {\n\t\t\tlatestUpdate.subEvents.push({\n\t\t\t\ttype: `atom_update`,\n\t\t\t\ttoken: atomToken,\n\t\t\t\tupdate: eventOrUpdate,\n\t\t\t\ttimestamp: Date.now(), // 👺 use store operation\n\t\t\t})\n\t\t}\n\n\t\taddToHistory(tl, latestUpdate)\n\t\ttl.selectorTime = currentSelectorTime\n\n\t\tstore.logger.info(\n\t\t\t`⌛`,\n\t\t\t`timeline`,\n\t\t\ttl.key,\n\t\t\t`got a selector_update \"${currentSelectorToken.key}\" with`,\n\t\t\tlatestUpdate.subEvents.map((event) => event.token.key),\n\t\t)\n\n\t\tconst operation = store.operation\n\t\tconst unsub = store.on.operationClose.subscribe(\n\t\t\t`timeline:${tl.key} (needs to gather nested selector creations)`,\n\t\t\t() => {\n\t\t\t\tunsub()\n\t\t\t\tif (operation.open) {\n\t\t\t\t\tselectorUpdate.subEvents = [\n\t\t\t\t\t\t...operation.subEvents,\n\t\t\t\t\t\t...selectorUpdate.subEvents,\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t} else {\n\t\tif (latestUpdate?.type === `selector_update`) {\n\t\t\tif (`type` in eventOrUpdate) {\n\t\t\t\tlatestUpdate.subEvents.push(eventOrUpdate)\n\t\t\t} else {\n\t\t\t\tlatestUpdate.subEvents.push({\n\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\ttoken: atomToken,\n\t\t\t\t\tupdate: eventOrUpdate,\n\t\t\t\t\ttimestamp: Date.now(), // 👺 use store operation\n\t\t\t\t})\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⌛`,\n\t\t\t\t`timeline`,\n\t\t\t\ttl.key,\n\t\t\t\t`set selector_update \"${currentSelectorToken.key}\" to`,\n\t\t\t\tlatestUpdate?.subEvents.map((event) => event.token.key),\n\t\t\t)\n\t\t}\n\t}\n\tif (latestUpdate) {\n\t\ttl.subject.next(latestUpdate)\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\tconst currentSelectorToken =\n\t\tstore.operation.open &&\n\t\tstore.operation.token.type === `writable_pure_selector`\n\t\t\t? store.operation.token\n\t\t\t: null\n\tconst currentSelectorTime =\n\t\tstore.operation.open &&\n\t\tstore.operation.token.type === `writable_pure_selector`\n\t\t\t? store.operation.timestamp\n\t\t\t: null\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 if (\n\t\t\t\tcurrentSelectorToken &&\n\t\t\t\tcurrentSelectorTime &&\n\t\t\t\tevent.type === `state_creation`\n\t\t\t) {\n\t\t\t\tbuildSelectorUpdate(\n\t\t\t\t\tstore,\n\t\t\t\t\ttl,\n\t\t\t\t\tevent.token,\n\t\t\t\t\tevent,\n\t\t\t\t\tcurrentSelectorToken,\n\t\t\t\t\tcurrentSelectorTime,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\taddToHistory(tl, 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\nfunction addToHistory(tl: Timeline<any>, event: TimelineEvent<any>): void {\n\tif (tl.at !== tl.history.length) {\n\t\ttl.history.splice(tl.at)\n\t}\n\ttl.history.push(event)\n\ttl.at = tl.history.length\n\ttl.subject.next(event)\n}\n","import type { TimelineEvent, TimelineToken } from \"atom.io\"\n\nimport {\n\tingestAtomUpdateEvent,\n\tingestCreationEvent,\n\tingestDisposalEvent,\n\tingestSelectorUpdateEvent,\n\tingestTransactionOutcomeEvent,\n} from \"../events\"\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\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\tlet nextIndex = timelineData.at\n\tlet events: TimelineEvent<any>[]\n\tswitch (action) {\n\t\tcase `undo`:\n\t\t\t--nextIndex\n\t\t\twhile (\n\t\t\t\tnextIndex !== 0 &&\n\t\t\t\ttimelineData.history[nextIndex].checkpoint !== true\n\t\t\t) {\n\t\t\t\t--nextIndex\n\t\t\t}\n\t\t\tevents = timelineData.history.slice(nextIndex, timelineData.at).reverse()\n\n\t\t\tbreak\n\t\tcase `redo`:\n\t\t\t++nextIndex\n\t\t\tevents = timelineData.history.slice(timelineData.at, nextIndex)\n\t}\n\ttimelineData.at = nextIndex\n\n\tconst applying = action === `redo` ? `newValue` : `oldValue`\n\n\tfor (const event of events) {\n\t\tswitch (event.type) {\n\t\t\tcase `atom_update`: {\n\t\t\t\tingestAtomUpdateEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `selector_update`: {\n\t\t\t\tingestSelectorUpdateEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `transaction_outcome`: {\n\t\t\t\tingestTransactionOutcomeEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `state_creation`: {\n\t\t\t\tingestCreationEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `state_disposal`: {\n\t\t\t\tingestDisposalEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\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,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;;;;;ACKtC,SAAgB,OACf,OACgC;AAChC,QAAO,MAAM,UAAU,KACtB,SAAQ,MAAM;AAEf,QAAO;;AAGR,SAAgB,OACf,OAC0C;AAC1C,QAAO,MAAM,WAAW,KACvB,SAAQ,MAAM;AAEf,QAAO;;;;;ACnBR,MAAM,oBACL;AAED,SAAgB,KAAK,OAA6B;CACjD,MAAM,cAAc,OAAO,UAAU,SAAS,KAAK,MAAM;AACzD,QAAO,kBAAkB,KAAK,YAAY;;;;;ACL3C,SAAgB,OACf,oBACA,eACI;AACJ,KAAI,KAAK,mBAAmB,CAC3B,QAAO,mBAAmB,cAAc;AAEzC,QAAO;;;;;;;;;;;;;;ACAR,IAAa,SAAb,cAA+B,QAAW;CACzC,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,OAA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U,aAAa,OAAO,aAAa,QAAQ,UAC9D,WAAW,UAAU,aAAa,OAAO,GACzC;AACD,QAAM,OAAO,KACZ,MACA,YACA,MAAM,KACN,aAAa,OAAO,UACnB,WAAW,SAAS,QAAQ,YAC5B,gBAAgB,MAAM,IAAI,yBAAyB,OAAO,GAC3D;AACD;;AAGD,cAAa,gBAAgB,WAAW,SAAS,gBAAgB;CACjE,IAAI,YAAY,aAAa;CAC7B,IAAIC;AACJ,SAAQ,QAAR;EACC,KAAK;AACJ,KAAE;AACF,UACC,cAAc,KACd,aAAa,QAAQ,WAAW,eAAe,KAE/C,GAAE;AAEH,YAAS,aAAa,QAAQ,MAAM,WAAW,aAAa,GAAG,CAAC,SAAS;AAEzE;EACD,KAAK;AACJ,KAAE;AACF,YAAS,aAAa,QAAQ,MAAM,aAAa,IAAI,UAAU;;AAEjE,cAAa,KAAK;CAElB,MAAM,WAAW,WAAW,SAAS,aAAa;AAElD,MAAK,MAAM,SAAS,OACnB,SAAQ,MAAM,MAAd;EACC,KAAK;AACJ,yBAAsB,OAAO,OAAO,SAAS;AAC7C;EAED,KAAK;AACJ,6BAA0B,OAAO,OAAO,SAAS;AACjD;EAED,KAAK;AACJ,iCAA8B,OAAO,OAAO,SAAS;AACrD;EAED,KAAK;AACJ,uBAAoB,OAAO,OAAO,SAAS;AAC3C;EAED,KAAK;AACJ,uBAAoB,OAAO,OAAO,SAAS;AAC3C;;AAKH,cAAa,QAAQ,KAAK,OAAO;AACjC,cAAa,gBAAgB;AAC7B,OAAM,OAAO,KACZ,MACA,YACA,MAAM,KACN,IAAI,MAAM,IAAI,cAAc,aAAa,GAAG,KAAK,aAAa,QAAQ,SACtE"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["superResolve: ((value: T) => void) | undefined","superReject: ((reason?: any) => void) | undefined","length: number","a: A | undefined","b: B | undefined","a: A","b: B","content: Content | undefined","singleRelation: A | B | undefined","config: JunctionAdvancedConfiguration<AName, A, BName, B, Content>","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: (\n\t\t| AtomUpdateEvent<AtomOnly<TimelineManageable>>\n\t\t| StateCreationEvent<any>\n\t)[]","childBase: Omit<ChildStore, `transactionMeta`>","transactionMeta: TransactionProgress<Fn>","child: ChildStore","newTransaction: Transaction<F>","token","IMPLICIT: { readonly STORE: RootStore }","withdrawn: AtomIOInternalResource | undefined","target: Store | null","val: E | T","def: E | T","MUST_CREATE: unique symbol","DO_NOT_CREATE: unique symbol","token: ReadableToken<T, KK, E>","existingToken: ReadableToken<T, K, E> | undefined","brandNewToken: ReadableToken<T, K, E> | undefined","family: ReadableFamily<T, K, E> | undefined","subKey: K | undefined","token: ReadableToken<T, K, E>","subType: `readable` | `writable`","stateCreationEvent: StateCreationEvent<any>","state: ReadableState<any, any> | undefined","family: FamilyMetadata<Key>","individualOptions: ReadonlyPureSelectorOptions<T, E>","readonlySelectorFamily: ReadonlyPureSelectorFamily<T, K, E>","familyToken: RegularAtomFamilyToken<T, K, E>","family: FamilyMetadata<Key>","individualOptions: RegularAtomOptions<T, E>","atomFamily: RegularAtomFamily<T, K, E>","atomFamily","family: FamilyMetadata","readonlySelectorFamily: ReadonlyHeldSelectorFamily<T, K>","family: FamilyMetadata","selectorFamily: WritableHeldSelectorFamily<T, K>","selectorFamily","family: FamilyMetadata<Key>","individualOptions: WritablePureSelectorOptions<T, E>","selectorFamily: WritablePureSelectorFamily<T, K, E>","selectorFamily","token: ReadableToken<any, any, any>","stateCreationEvent: StateCreationEvent<any> & TimelineEvent<any>","update: StateUpdate<T>","atomUpdate: AtomUpdateEvent<any>","def: E | T","protoUpdate: ProtoUpdate<E | T>","RESET_STATE: unique symbol","oldValue: T","newValue: T","constant: T","protoUpdate: ProtoUpdate<T>","OWN_OP: unique symbol","JOIN_OP: unique symbol","existingToken: WritableToken<T, K, E> | undefined","brandNewToken: WritableToken<T, K, E> | undefined","token: WritableToken<T, K, E>","family: WritableFamily<T, K, E> | undefined","key: K | null","value: Setter<TT> | TT | typeof RESET_STATE","target: Store & { operation: OpenOperation }","protoUpdate: ProtoUpdate<E | T>","dependencyValue: unknown","readonlySelector: ReadonlyHeldSelector<T>","token: ReadonlyHeldSelectorToken<T>","readonlySelector: ReadonlyPureSelector<T, E>","token: ReadonlyPureSelectorToken<T>","mySelector: WritableHeldSelector<T>","token: WritableHeldSelectorToken<T>","mySelector: WritablePureSelector<T, E>","token: WritablePureSelectorToken<T>","state","familyToken: SelectorFamilyToken<any, any, any>","unsubscribe","updateHandler: UpdateHandler<E | T>","familyMetaData: FamilyMetadata | undefined","newAtom: MutableAtom<T>","cleanupFunctions: (() => void)[]","familyToken: MutableAtomFamilyToken<T & Transceiver<any, any, any>, K>","family: FamilyMetadata","individualOptions: MutableAtomOptions<T>","atomFamily: MutableAtomFamily<T, K>","atomFamily","jsonFamilyToken: WritablePureSelectorFamilyToken<AsJSON<T>, string>","updateToken: RegularAtomToken<SignalFrom<T>>","mutableAtom","newAtom: RegularAtom<T, E>","cleanupFunctions: (() => void)[]","disposalEvent: AtomDisposalEvent<AtomToken<any, any, any>>","aSide: AName","bSide: BName","replaceRelationsSafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t>","previousOwnersToDispose: string[]","previousOwnerSize: number | undefined","relations","replaceRelationsUnsafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t>","relations: JoinStates<AName, A, BName, B, Cardinality>","tl: Timeline<ManagedAtom>","atomToken: AtomToken<any, any, any>","familyToken: AtomFamilyToken<any, any, any>","token: TimelineToken<ManagedAtom>","atomUpdate: AtomUpdateEvent<any> & TimelineEvent<any>","timelineTransactionUpdate: TimelineEvent<any> &\n\t\t\t\t\t\tTransactionOutcomeEvent<TransactionToken<any>>","latestUpdate: TimelineEvent<any> | undefined","selectorUpdate: TimelineEvent<any> & TimelineSelectorUpdateEvent<any>","key: string","familyKey: string | undefined","events: TimelineEvent<any>[]"],"sources":["../../src/internal/arbitrary.ts","../../src/internal/lineage.ts","../../src/internal/is-fn.ts","../../src/internal/set-state/become.ts","../../src/internal/future.ts","../../src/internal/subject.ts","../../src/internal/store/circular-buffer.ts","../../src/internal/store/deposit.ts","../../src/internal/overlays/map-overlay.ts","../../src/internal/overlays/set-overlay.ts","../../src/internal/overlays/relations-overlay.ts","../../src/internal/junction.ts","../../src/internal/reserved-keys.ts","../../src/internal/transaction/abort-transaction.ts","../../src/internal/transaction/act-upon-store.ts","../../src/internal/events/ingest-atom-update.ts","../../src/internal/get-trace.ts","../../src/internal/molecule.ts","../../src/internal/events/ingest-creation-disposal.ts","../../src/internal/events/ingest-selector-update.ts","../../src/internal/events/ingest-transaction-update.ts","../../src/internal/transaction/is-root-store.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/transaction/build-transaction.ts","../../src/internal/transaction/create-transaction.ts","../../src/internal/transaction/transaction-meta-progress.ts","../../src/internal/store/store.ts","../../src/internal/not-found-error.ts","../../src/internal/store/withdraw.ts","../../src/internal/get-state/get-fallback.ts","../../src/internal/safe-compute.ts","../../src/internal/get-state/read-or-compute-value.ts","../../src/internal/families/get-family-of-token.ts","../../src/internal/families/mint-in-store.ts","../../src/internal/get-state/reduce-reference.ts","../../src/internal/get-state/get-from-store.ts","../../src/internal/families/seek-in-store.ts","../../src/internal/families/find-in-store.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/dispose-from-store.ts","../../src/internal/operation.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/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/subscribe/recall-state.ts","../../src/internal/subscribe/subscribe-to-root-atoms.ts","../../src/internal/subscribe/subscribe-to-state.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/caching.ts","../../src/internal/set-state/evict-downstream.ts","../../src/internal/atom/create-regular-atom.ts","../../src/internal/atom/has-role.ts","../../src/internal/atom/dispose-atom.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/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>(\n\tscion: T,\n): Exclude<T[`child`], null> | T {\n\twhile (scion.child !== null) {\n\t\tscion = scion.child\n\t}\n\treturn scion\n}\n\nexport function eldest<T extends Lineage>(\n\tscion: T,\n): Exclude<T[`parent`], T[`child`] | null> {\n\twhile (scion.parent !== null) {\n\t\tscion = scion.parent\n\t}\n\treturn scion as Exclude<T[`parent`], T[`child`] | null>\n}\n","import type { Fn } from \"./utility-types\"\n\nconst NON_CTOR_FN_REGEX =\n\t/^\\[object (?:Async|Generator|AsyncGenerator)?Function\\]$/\n\nexport function isFn(input: unknown): input is Fn {\n\tconst protoString = Object.prototype.toString.call(input)\n\treturn NON_CTOR_FN_REGEX.test(protoString)\n}\n","import { isFn } from \"../is-fn\"\n\nexport function become<T>(\n\tnextVersionOfThing: T | ((prev: T) => T),\n\toriginalThing: T,\n): T {\n\tif (isFn(nextVersionOfThing)) {\n\t\treturn nextVersionOfThing(originalThing)\n\t}\n\treturn nextVersionOfThing\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","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","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 { Transceiver } from \"../mutable\"\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tMutableAtom,\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadableState,\n\tReadonlyPureSelector,\n\tReadonlyPureSelectorFamily,\n\tRegularAtom,\n\tRegularAtomFamily,\n\tSelector,\n\tSelectorFamily,\n\tWritableFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableState,\n} from \"../state-types\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Fn } from \"../utility-types\"\n\nexport function deposit<T, E>(\n\tstate: RegularAtom<T, E>,\n): RegularAtomToken<T, Canonical, E>\nexport function deposit<T extends Transceiver<any, any, any>>(\n\tstate: MutableAtom<T>,\n): MutableAtomToken<T>\nexport function deposit<T, E>(state: Atom<T, E>): AtomToken<T, Canonical, E>\nexport function deposit<T, E>(\n\tstate: WritablePureSelector<T, E>,\n): WritablePureSelectorToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadonlyPureSelector<T, E>,\n): ReadonlyPureSelectorToken<T, any, E>\nexport function deposit<T, E>(state: Selector<T, E>): SelectorToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: WritableState<T, E>,\n): WritableToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadableState<T, E>,\n): ReadableToken<T, any, E>\n\nexport function deposit<T, K extends Canonical, E>(\n\tstate: RegularAtomFamily<T, K, E>,\n): RegularAtomFamilyToken<T, K, E>\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, E>(\n\tstate: AtomFamily<T, any, E>,\n): AtomFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: WritablePureSelectorFamily<T, any, E>,\n): WritablePureSelectorFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadonlyPureSelectorFamily<T, any, E>,\n): ReadonlyPureSelectorFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: SelectorFamily<T, any, E>,\n): SelectorFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: WritableFamily<T, any, E>,\n): WritableFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadableFamily<T, any, E>,\n): ReadableFamilyToken<T, any, E>\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","export class MapOverlay<K, V> extends Map<K, V> {\n\tpublic deleted: Set<K> = new Set()\n\tpublic changed: 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\tif (this.source.has(key)) {\n\t\t\tthis.changed.add(key)\n\t\t}\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\tif (this.source.has(key)) {\n\t\t\tthis.deleted.add(key)\n\t\t\tthis.changed.delete(key)\n\t\t}\n\t\treturn super.delete(key)\n\t}\n\n\tpublic clear(): void {\n\t\tthis.deleted = new Set(this.source.keys())\n\t\tthis.changed.clear()\n\t\tsuper.clear()\n\t}\n\n\tpublic *[Symbol.iterator](): MapIterator<[K, V]> {\n\t\tyield* super[Symbol.iterator]()\n\t\tfor (const [key, value] of this.source) {\n\t\t\tif (!this.deleted.has(key) && !this.changed.has(key)) {\n\t\t\t\tyield [key, value]\n\t\t\t}\n\t\t}\n\t}\n\tpublic *entries(): MapIterator<[K, V]> {\n\t\tyield* this[Symbol.iterator]()\n\t}\n\tpublic *keys(): MapIterator<K> {\n\t\tyield* super.keys()\n\t\tfor (const key of this.source.keys()) {\n\t\t\tif (!this.deleted.has(key) && !this.changed.has(key)) {\n\t\t\t\tyield key\n\t\t\t}\n\t\t}\n\t}\n\tpublic *values(): MapIterator<V> {\n\t\tfor (const [, value] of this[Symbol.iterator]()) {\n\t\t\tyield value\n\t\t}\n\t}\n\tpublic forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void): void {\n\t\tfor (const [key, value] of this[Symbol.iterator]()) {\n\t\t\tcallbackfn(value, key, this)\n\t\t}\n\t}\n\n\tpublic get size(): number {\n\t\treturn super.size + this.source.size - this.changed.size - this.deleted.size\n\t}\n}\n","export class SetOverlay<T> extends Set<T> {\n\tpublic deleted: Set<T> = new Set()\n\tpublic source: Set<T>\n\n\tpublic constructor(source: Set<T>) {\n\t\tsuper()\n\t\tthis.source = source\n\t}\n\n\tpublic add(value: T): this {\n\t\tif (this.source.has(value)) {\n\t\t\tthis.deleted.delete(value)\n\t\t\treturn this\n\t\t}\n\t\treturn super.add(value)\n\t}\n\n\tpublic hasOwn(member: T): boolean {\n\t\treturn super.has(member)\n\t}\n\n\tpublic has(key: T): boolean {\n\t\treturn !this.deleted.has(key) && (super.has(key) || this.source.has(key))\n\t}\n\n\tpublic delete(key: T): boolean {\n\t\tif (this.source.has(key)) {\n\t\t\tthis.deleted.add(key)\n\t\t\treturn true\n\t\t}\n\t\treturn super.delete(key)\n\t}\n\n\tpublic clear(): void {\n\t\tthis.deleted = new Set(this.source)\n\t\tsuper.clear()\n\t}\n\n\tpublic *[Symbol.iterator](): SetIterator<T> {\n\t\tyield* super[Symbol.iterator]()\n\t\tfor (const value of this.source) {\n\t\t\tif (!this.deleted.has(value)) {\n\t\t\t\tyield value\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic *iterateOwn(): SetIterator<T> {\n\t\tyield* super[Symbol.iterator]()\n\t}\n\n\tpublic get size(): number {\n\t\treturn super.size + this.source.size - this.deleted.size\n\t}\n}\n","import { SetOverlay } from \"./set-overlay\"\n\nexport class RelationsOverlay<K, V extends Set<any>> 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\tconst valueOverlay = new SetOverlay(value as V) as unknown as V\n\t\t\tsuper.set(key, valueOverlay)\n\t\t\treturn valueOverlay\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 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 { Json } from \"atom.io/json\"\n\nimport { MapOverlay, RelationsOverlay, SetOverlay } from \"./overlays\"\nimport type { Refinement } from \"./utility-types\"\n\nexport type JunctionEntriesBase<\n\tA extends string,\n\tB extends string,\n\tContent extends Json.Object | null,\n> = {\n\treadonly relations: ([A, B[]] | [B, A[]])[]\n\treadonly contents: [string, Content][]\n}\nexport interface JunctionEntries<\n\tA extends string,\n\tB extends string,\n\tContent extends Json.Object | null,\n> extends Json.Object,\n\t\tJunctionEntriesBase<A, B, Content> {}\n\nexport type JunctionSchemaBase<AName extends string, BName extends string> = {\n\t/** Description of the relationship between the two sides */\n\treadonly between: [a: AName, b: BName]\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\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tContent extends Json.Object | null,\n> = {\n\twarn?: (...args: any[]) => void\n\texternalStore?: ExternalStoreConfiguration<Content>\n\tisAType?: Refinement<string, A>\n\tisBType?: Refinement<string, B>\n\tisContent?: Refinement<unknown, Content>\n\tmakeContentKey?: (a: A, b: B) => string\n\tsource?: Junction<AName, A, BName, B, Content>\n}\n\nexport type JunctionJSON<\n\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tContent extends Json.Object | null,\n> = JunctionEntries<A, B, Content> & JunctionSchema<AName, BName>\n\nexport class Junction<\n\tconst AName extends string,\n\tconst A extends string,\n\tconst BName extends string,\n\tconst B extends string,\n\tconst Content extends Json.Object | null = null,\n> {\n\tpublic readonly a: AName\n\tpublic readonly b: BName\n\tpublic readonly cardinality: `1:1` | `1:n` | `n:n`\n\tpublic readonly relations: Map<A | B, Set<A> | Set<B>> = new Map()\n\tpublic readonly contents: Map<string, Content> = new Map()\n\n\tpublic isAType?: Refinement<string, A> | null\n\tpublic isBType?: Refinement<string, B> | null\n\tpublic isContent: Refinement<unknown, Content> | null\n\tpublic makeContentKey = (a: A, b: B): string => `${a}:${b}`\n\n\tpublic warn?: (...args: any[]) => void\n\n\tpublic getRelatedKeys(key: A): Set<B> | undefined\n\tpublic getRelatedKeys(key: B): Set<A> | undefined\n\tpublic getRelatedKeys(key: A | B): Set<A> | Set<B> | undefined\n\tpublic getRelatedKeys(key: A | B): Set<A> | Set<B> | undefined {\n\t\treturn this.relations.get(key)\n\t}\n\tprotected addRelation(a: A, b: B): void {\n\t\tlet aRelations = this.relations.get(a) as Set<B> | undefined\n\t\tlet bRelations = this.relations.get(b) as Set<A> | 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: A, b: B): void {\n\t\tconst aRelations = this.relations.get(a) as Set<B> | 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<A> | 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: A, bs: B[]): void\n\tprotected replaceRelationsUnsafely(b: B, as: A[]): void\n\tprotected replaceRelationsUnsafely(x: A | B, ys: A[] | B[]): void {\n\t\tthis.relations.set(x as A, new Set(ys as B[]))\n\t\tfor (const y of ys) {\n\t\t\tconst yRelations = new Set<A>().add(x as A)\n\t\t\tthis.relations.set(y, yRelations)\n\t\t}\n\t}\n\tprotected replaceRelationsSafely(a: A, bs: B[]): void\n\tprotected replaceRelationsSafely(b: B, as: A[]): void\n\tprotected replaceRelationsSafely<\n\t\tXType extends A | B,\n\t\tYType extends XType extends A ? B : A,\n\t>(x: XType, ys: YType[]): void {\n\t\tconst xRelationsPrev = this.relations.get(x)\n\t\tlet a: A | undefined = this.isAType?.(x) ? x : undefined\n\t\tlet b: B | undefined = a === undefined ? (x as B) : undefined\n\t\tif (xRelationsPrev) {\n\t\t\tfor (const y of xRelationsPrev) {\n\t\t\t\ta ??= y as A\n\t\t\t\tb ??= y as B\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<AName, BName> &\n\t\t\tPartial<JunctionEntries<NoInfer<A>, NoInfer<B>, Content>>,\n\t\tconfig?: JunctionAdvancedConfiguration<AName, A, BName, B, 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\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 source = config?.source\n\t\t\tif (source === undefined) {\n\t\t\t\tthis.relations = new Map(\n\t\t\t\t\tdata.relations?.map(([x, ys]) => [x, new Set(ys as A[])]),\n\t\t\t\t)\n\t\t\t\tthis.contents = new Map(data.contents)\n\t\t\t}\n\t\t\tif (source) {\n\t\t\t\tthis.relations = new RelationsOverlay(source.relations)\n\t\t\t\tthis.contents = new MapOverlay(source.contents)\n\t\t\t}\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 B) : undefined\n\t\t\t\tfor (const y of ys) {\n\t\t\t\t\ta ??= y as A\n\t\t\t\t\tb ??= y as B\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<AName, A, BName, B, 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 [A, B[]],\n\t\t\t),\n\t\t\tcontents: [...this.contents.entries()],\n\t\t}\n\t}\n\n\tpublic set(\n\t\ta: A,\n\t\t...rest: Content extends null ? [b: B] : [b: B, content: Content]\n\t): this\n\tpublic set(\n\t\trelation: { [Key in AName]: A } & { [Key in BName]: B },\n\t\t...rest: Content extends null ? [] | [void?: undefined] : [content: Content]\n\t): this\n\tpublic set(\n\t\t...params:\n\t\t\t| [\n\t\t\t\t\trelation: { [Key in AName]: A } & { [Key in BName]: B },\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\t| [a: A, ...rest: Content extends null ? [b: B] : [b: B, content: Content]]\n\t): this {\n\t\tlet a: A\n\t\tlet b: B\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<AName, A> & Record<BName, B>\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 [A, B]\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 A\n\t\t\t\tb = params[1] as B\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: A, b?: B): this\n\tpublic delete(b: B, a?: A): this\n\tpublic delete(\n\t\trelation:\n\t\t\t| { [Key in AName]: A }\n\t\t\t| { [Key in BName]: B }\n\t\t\t| ({ [Key in AName]: A } & { [Key in BName]: B }),\n\t\tb?: undefined,\n\t): this\n\tpublic delete(\n\t\tx:\n\t\t\t| A\n\t\t\t| B\n\t\t\t| Record<AName | BName, string>\n\t\t\t| Record<AName, string>\n\t\t\t| Record<BName, string>,\n\t\tb?: A | B,\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 B) : (x[this.b] as B | 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 A) : (x[this.a] as A | undefined)\n\n\t\tif (a === undefined && typeof b === `string`) {\n\t\t\tconst bRelations = this.getRelatedKeys(b) as Set<A>\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} else if (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} else if (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: A): B | undefined\n\tpublic getRelatedKey(key: B): A | undefined\n\tpublic getRelatedKey(key: A | B): A | B | 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: A | B | 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: A,\n\t\trelations: Content extends null ? B[] : Record<B, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this\n\tpublic replaceRelations(\n\t\tb: B,\n\t\trelations: Content extends null ? A[] : Record<A, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this\n\tpublic replaceRelations<\n\t\tXType extends A | B,\n\t\tYType extends XType extends A ? B : A,\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: A, b: B): Content | undefined {\n\t\tconst contentKey = this.makeContentKey(a, b)\n\t\treturn this.getContentInternal(contentKey)\n\t}\n\n\tpublic getRelationEntries(input: Record<AName, A>): [B, Content][]\n\tpublic getRelationEntries(input: Record<BName, B>): [A, Content][]\n\tpublic getRelationEntries(\n\t\tinput: Record<AName, A> | Record<BName, B>,\n\t): [A | B, Content][] {\n\t\tconst a: A | undefined = (input as any)[this.a]\n\t\tconst b: B | 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: A, b?: B): boolean\n\tpublic has(b: B, a?: A): boolean\n\tpublic has(a: A | B, b?: A | B): 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\tpublic overlay(): JunctionOverlay<AName, A, BName, B, Content> {\n\t\tconst config: JunctionAdvancedConfiguration<AName, A, BName, B, Content> = {\n\t\t\tsource: this,\n\t\t\tmakeContentKey: this.makeContentKey,\n\t\t}\n\t\tif (this.isAType) config.isAType = this.isAType\n\t\tif (this.isBType) config.isBType = this.isBType\n\t\tif (this.isContent) config.isContent = this.isContent\n\t\tif (this.warn) config.warn = this.warn\n\n\t\treturn new Junction(\n\t\t\t{\n\t\t\t\tbetween: [this.a, this.b],\n\t\t\t\tcardinality: this.cardinality,\n\t\t\t},\n\t\t\tconfig,\n\t\t) as JunctionOverlay<AName, A, BName, B, Content>\n\t}\n\tpublic incorporate(\n\t\toverlay: JunctionOverlay<AName, A, BName, B, Content>,\n\t): void {\n\t\tconst { relations, contents } = overlay\n\t\tfor (const [key, value] of relations) {\n\t\t\tif (value instanceof SetOverlay) {\n\t\t\t\tconst { source } = value\n\t\t\t\tfor (const keyAdded of value.iterateOwn()) {\n\t\t\t\t\tsource.add(keyAdded)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.relations.set(key, value)\n\t\t\t}\n\t\t}\n\t\tfor (const key of relations.deleted) {\n\t\t\tthis.relations.delete(key)\n\t\t}\n\t\tfor (const [key, value] of contents) {\n\t\t\tthis.contents.set(key, value)\n\t\t}\n\t\tfor (const key of contents.deleted) {\n\t\t\tthis.contents.delete(key)\n\t\t}\n\t}\n}\n\nexport type JunctionOverlay<\n\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tContent extends Json.Object | null = null,\n> = Junction<AName, A, BName, B, Content> & {\n\trelations: MapOverlay<A | B, Set<A> | Set<B>>\n\tcontents: MapOverlay<string, Content>\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 { ChildStore } from \"./is-root-store\"\n\nexport const abortTransaction = (target: ChildStore): void => {\n\ttarget.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 { TransactionToken } from \"atom.io\"\n\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\treturn tx.run(parameters, id)\n\t}\n}\n","import type { AtomUpdateEvent } from \"atom.io\"\n\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\n\nexport function ingestAtomUpdateEvent(\n\tstore: Store,\n\tevent: AtomUpdateEvent<any>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tconst {\n\t\ttoken,\n\t\tupdate: { newValue, oldValue },\n\t} = event\n\tconst value = applying === `newValue` ? newValue : oldValue\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\tTransactionToken,\n\tVassal,\n} from \"atom.io\"\nimport type { Canonical, stringified } from \"atom.io/json\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\n\nimport { disposeFromStore } from \"./families\"\nimport { getFromStore } from \"./get-state\"\nimport { getTrace } from \"./get-trace\"\nimport { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\nimport type { RootStore } from \"./transaction\"\nimport { createTransaction, 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\tstore: Store,\n\tkey: S,\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 createDeallocateTX<\n\tH extends Hierarchy,\n\tV extends Exclude<Vassal<H>, CompoundTypedKey>,\n>(store: RootStore): TransactionToken<(claim: Claim<V>) => void> {\n\treturn createTransaction(store, {\n\t\tkey: `[Internal] deallocate`,\n\t\tdo: (_, claim: Claim<V>): void => {\n\t\t\tdeallocateFromStore<H, V>(newest(store), claim)\n\t\t},\n\t})\n}\n\nexport function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(\n\ttarget: Store,\n\tclaim: Claim<V>,\n): void {\n\tconst stringKey = stringifyJson(claim)\n\n\tconst molecule = target.molecules.get(stringKey)\n\tif (!molecule) {\n\t\tconst disposal = target.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === stringKey,\n\t\t)\n\t\ttarget.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 \"${target.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 = target.moleculeJoins.getRelatedKeys(stringKey)\n\tif (joinKeys) {\n\t\tfor (const joinKey of joinKeys) {\n\t\t\tconst join = target.joins.get(joinKey)\n\t\t\tif (join) {\n\t\t\t\tjoin.relations.delete(claim)\n\t\t\t}\n\t\t}\n\t}\n\ttarget.moleculeJoins.delete(stringKey)\n\n\tconst provenance: stringified<Canonical>[] = []\n\n\tconst values: [string, any][] = []\n\n\tconst relatedMolecules = target.moleculeGraph.getRelationEntries({\n\t\tdownstreamMoleculeKey: stringKey,\n\t})\n\tif (relatedMolecules) {\n\t\tfor (const [relatedStringKey, { source }] of relatedMolecules) {\n\t\t\tif (source === stringKey) {\n\t\t\t\tconst relatedKey = parseJson(relatedStringKey)\n\t\t\t\tdeallocateFromStore<any, any>(target, 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 value = getFromStore(target, family, claim)\n\t\t\tvalues.push([family.key, value])\n\t\t\tdisposeFromStore(target, family, claim)\n\t\t}\n\t}\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\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\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\ttarget.disposalTraces.add({ key: stringKey, trace })\n}\n\nexport function createClaimTX<\n\tH extends Hierarchy,\n\tV extends Exclude<Vassal<H>, CompoundTypedKey>,\n\tA extends Above<V, H>,\n>(\n\tstore: RootStore,\n): TransactionToken<\n\t(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`) => void\n> {\n\treturn createTransaction(store, {\n\t\tkey: `[Internal] claim`,\n\t\tdo: (_, newProvenance, claim, exclusive) => {\n\t\t\tclaimWithinStore<H, V, A>(store, newProvenance, claim, exclusive)\n\t\t},\n\t})\n}\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 { getFromStore } from \"../get-state\"\nimport {\n\tallocateIntoStore,\n\tclaimWithinStore,\n\tdeallocateFromStore,\n} from \"../molecule\"\nimport { setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\n\nexport function ingestCreationEvent(\n\tstore: Store,\n\tevent: StateCreationEvent<any>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`: {\n\t\t\tcreateInStore(store, event)\n\t\t\tbreak\n\t\t}\n\t\tcase `oldValue`: {\n\t\t\tdisposeFromStore(store, event.token)\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nexport function ingestDisposalEvent(\n\tstore: Store,\n\tevent: StateDisposalEvent<ReadableToken<any, any, any>>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`: {\n\t\t\tdisposeFromStore(store, event.token)\n\t\t\tbreak\n\t\t}\n\t\tcase `oldValue`: {\n\t\t\tcreateInStore(store, event)\n\t\t\tif (event.subType === `atom`) {\n\t\t\t\tstore.valueMap.set(event.token.key, event.value)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nfunction createInStore(\n\tstore: Store,\n\tevent: StateCreationEvent<any> | StateDisposalEvent<any>,\n): void {\n\tconst { token } = event\n\tif (event.subType === `writable` && event.value) {\n\t\tsetIntoStore(store, token, event.value)\n\t} else {\n\t\tgetFromStore(store, token)\n\t}\n}\n\nexport function ingestMoleculeCreationEvent(\n\tstore: Store,\n\tevent: MoleculeCreationEvent,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\tallocateIntoStore<any, any, any>(store, event.provenance, event.key)\n\t\t\tbreak\n\n\t\tcase `oldValue`:\n\t\t\tdeallocateFromStore<any, any>(store, event.key)\n\t\t\tbreak\n\t}\n}\nexport function ingestMoleculeDisposalEvent(\n\tstore: Store,\n\tevent: MoleculeDisposalEvent,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\tdeallocateFromStore<any, any>(store, event.key)\n\t\t\tbreak\n\n\t\tcase `oldValue`:\n\t\t\t{\n\t\t\t\tconst provenanceJson = event.provenance.map(parseJson)\n\t\t\t\tallocateIntoStore<any, any, any>(store, provenanceJson, event.key)\n\t\t\t\tfor (const [familyKey, value] of event.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\tgetFromStore(store, family, event.key)\n\t\t\t\t\t\tconst memberKey = `${familyKey}(${stringifyJson(event.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\tstore: Store,\n\tevent: MoleculeTransferEvent,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tswitch (applying) {\n\t\tcase `newValue`:\n\t\t\t{\n\t\t\t\tfor (const newOwner of event.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\tevent.key,\n\t\t\t\t\t\tevent.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 event.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\tevent.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\tStateCreationEvent,\n\tTimelineManageable,\n\tTimelineSelectorUpdateEvent,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdateEvent } from \"./ingest-atom-update\"\nimport { ingestCreationEvent } from \"./ingest-creation-disposal\"\n\nexport function ingestSelectorUpdateEvent(\n\tstore: Store,\n\tselectorUpdate: TimelineSelectorUpdateEvent<any>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tlet updates: (\n\t\t| AtomUpdateEvent<AtomOnly<TimelineManageable>>\n\t\t| StateCreationEvent<any>\n\t)[]\n\tif (applying === `newValue`) {\n\t\tupdates = selectorUpdate.subEvents\n\t} else {\n\t\tupdates = selectorUpdate.subEvents.toReversed()\n\t}\n\tfor (const atomUpdate of updates) {\n\t\tif (atomUpdate.type === `state_creation`) {\n\t\t\tingestCreationEvent(store, atomUpdate, applying)\n\t\t} else {\n\t\t\tingestAtomUpdateEvent(store, atomUpdate, applying)\n\t\t}\n\t}\n}\n","import type { TransactionOutcomeEvent } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdateEvent } from \"./ingest-atom-update\"\nimport {\n\tingestCreationEvent,\n\tingestDisposalEvent,\n\tingestMoleculeCreationEvent,\n\tingestMoleculeDisposalEvent,\n\tingestMoleculeTransferEvent,\n} from \"./ingest-creation-disposal\"\n\nexport function ingestTransactionOutcomeEvent(\n\tstore: Store,\n\tevent: TransactionOutcomeEvent<any>,\n\tapplying: `newValue` | `oldValue`,\n): void {\n\tconst subEvents =\n\t\tapplying === `newValue` ? event.subEvents : [...event.subEvents].reverse()\n\tfor (const subEvent of subEvents) {\n\t\tswitch (subEvent.type) {\n\t\t\tcase `atom_update`:\n\t\t\t\tingestAtomUpdateEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `state_creation`:\n\t\t\t\tingestCreationEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `state_disposal`:\n\t\t\t\tingestDisposalEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `molecule_creation`:\n\t\t\t\tingestMoleculeCreationEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `molecule_disposal`:\n\t\t\t\tingestMoleculeDisposalEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `molecule_transfer`:\n\t\t\t\tingestMoleculeTransferEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t\tcase `transaction_outcome`:\n\t\t\t\tingestTransactionOutcomeEvent(store, subEvent, applying)\n\t\t\t\tbreak\n\t\t}\n\t}\n}\n","import type { MapOverlay } from \"../overlays/map-overlay\"\nimport type { Store } from \"../store\"\nimport type { Fn } from \"../utility-types\"\nimport type {\n\tTransactionEpoch,\n\tTransactionProgress,\n} from \"./transaction-meta-progress\"\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: MapOverlay<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 { RootStore } 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: RootStore,\n\ttransactionKey: string,\n): number | undefined {\n\tconst continuityKey = getContinuityKey(store, transactionKey)\n\tif (continuityKey === undefined) {\n\t\treturn undefined\n\t}\n\treturn getEpochNumberOfContinuity(store, continuityKey)\n}\n","import { getContinuityKey } from \"./get-epoch-number\"\nimport type { RootStore } from \"./is-root-store\"\n\nexport function setEpochNumberOfContinuity(\n\tstore: RootStore,\n\tcontinuityKey: string,\n\tnewEpoch: number,\n): void {\n\tstore.transactionMeta.epoch.set(continuityKey, newEpoch)\n}\n\nexport function setEpochNumberOfAction(\n\tstore: RootStore,\n\ttransactionKey: string,\n\tnewEpoch: number,\n): void {\n\tconst continuityKey = getContinuityKey(store, transactionKey)\n\n\tif (continuityKey !== undefined) {\n\t\tstore.transactionMeta.epoch.set(continuityKey, newEpoch)\n\t}\n}\n","import { ingestTransactionOutcomeEvent } from \"../events\"\nimport { newest } from \"../lineage\"\nimport { withdraw } from \"../store\"\nimport type { Fn } from \"../utility-types\"\nimport type { ChildStore } from \"./is-root-store\"\nimport { isChildStore, isRootStore } from \"./is-root-store\"\nimport { setEpochNumberOfAction } from \"./set-epoch-number\"\n\nexport function applyTransaction<F extends Fn>(\n\tstore: ChildStore,\n\toutput: ReturnType<F>,\n): void {\n\tconst child = newest(store)\n\tconst { parent } = child\n\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 ${updates.length} subEvents:`,\n\t\tupdates,\n\t)\n\n\tingestTransactionOutcomeEvent(parent, child.transactionMeta.update, `newValue`)\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`applied`,\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 { RootStore } from \"./is-root-store\"\n\nexport function assignTransactionToContinuity(\n\tstore: RootStore,\n\tcontinuityKey: string,\n\ttransactionKey: string,\n): void {\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","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 { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { MapOverlay } from \"../overlays/map-overlay\"\nimport { resetInStore, setIntoStore } from \"../set-state\"\nimport type { Fn } from \"../utility-types\"\nimport { actUponStore } from \"./act-upon-store\"\nimport { getEpochNumberOfAction } from \"./get-epoch-number\"\nimport type { ChildStore, RootStore } from \"./is-root-store\"\nimport type { TransactionProgress } from \"./transaction-meta-progress\"\n\nexport const buildTransaction = (\n\tstore: RootStore,\n\ttoken: TransactionToken<any>,\n\tparams: any[],\n\tid: string,\n): ChildStore => {\n\tconst parent = newest(store)\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 MapOverlay(parent.atoms),\n\t\tatomsThatAreDefault: new Set(parent.atomsThatAreDefault),\n\t\tfamilies: new MapOverlay(parent.families),\n\t\tjoins: new MapOverlay(parent.joins),\n\t\toperation: { open: false },\n\t\treadonlySelectors: new MapOverlay(parent.readonlySelectors),\n\t\ttimelines: new MapOverlay(parent.timelines),\n\t\ttimelineTopics: parent.timelineTopics.overlay(),\n\t\ttrackers: new Map(),\n\t\ttransactions: new MapOverlay(parent.transactions),\n\t\tselectorAtoms: parent.selectorAtoms.overlay(),\n\t\tselectorGraph: parent.selectorGraph.overlay(),\n\t\twritableSelectors: new MapOverlay(parent.writableSelectors),\n\t\tvalueMap: new MapOverlay(parent.valueMap),\n\t\tdefaults: parent.defaults,\n\t\tdisposalTraces: store.disposalTraces.copy(),\n\t\tmolecules: new MapOverlay(parent.molecules),\n\t\tmoleculeGraph: parent.moleculeGraph.overlay(),\n\t\tmoleculeData: parent.moleculeData.overlay(),\n\t\tmoleculeJoins: parent.moleculeJoins.overlay(),\n\t\tmiscResources: new MapOverlay(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 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 { 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\"\nimport type { RootStore } from \"./is-root-store\"\n\nexport type Transaction<F extends Fn> = {\n\tkey: string\n\ttype: `transaction`\n\tinstall: (store: RootStore) => 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: RootStore,\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 target = buildTransaction(store, token, params, id)\n\t\t\ttry {\n\t\t\t\tconst { toolkit } = target.transactionMeta\n\t\t\t\tconst output = options.do(toolkit, ...params)\n\t\t\t\tapplyTransaction<F>(target, output)\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 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\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 { 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 { isReservedIntrospectionKey } from \"../reserved-keys\"\nimport type {\n\tAtom,\n\tHeldSelectorFamily,\n\tMutableAtomFamily,\n\tPureSelectorFamily,\n\tReadonlySelector,\n\tRegularAtomFamily,\n\tWritableSelector,\n} from \"../state-types\"\nimport { StatefulSubject, Subject } from \"../subject\"\nimport type { Timeline } from \"../timeline\"\nimport type {\n\tChildStore,\n\tRootStore,\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: ChildStore | RootStore | null = null\n\tpublic child: ChildStore | 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, any>> = new Map()\n\tpublic writableSelectors: Map<string, WritableSelector<any, any>> = new Map()\n\tpublic readonlySelectors: Map<string, ReadonlySelector<any, 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, any>\n\t\t| RegularAtomFamily<any, any, any>\n\t> = new Map()\n\tpublic joins: Map<string, Join<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 as RootStore)\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 as RootStore)\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 as RootStore)\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 as RootStore)\n\t\t\t}\n\t\t\tfor (const [, tx] of store.transactions) {\n\t\t\t\ttx.install(this as RootStore)\n\t\t\t}\n\t\t\tfor (const [, timeline] of store.timelines) {\n\t\t\t\ttimeline.install(this as RootStore)\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport type StoreEventCarrier = {\n\tatomCreation: Subject<AtomToken<unknown, any, any>>\n\tatomDisposal: Subject<AtomToken<unknown, any, any>>\n\tselectorCreation: Subject<SelectorToken<unknown, any, any>>\n\tselectorDisposal: Subject<SelectorToken<unknown, any, any>>\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: RootStore | undefined\n}\n\nexport const IMPLICIT: { readonly STORE: RootStore } = {\n\tget STORE(): RootStore {\n\t\tglobalThis.ATOM_IO_IMPLICIT_STORE ??= new Store({\n\t\t\tname: `IMPLICIT_STORE`,\n\t\t\tlifespan: `ephemeral`,\n\t\t}) as RootStore\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 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 {\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 { Transceiver } from \"../mutable\"\nimport { NotFoundError } from \"../not-found-error\"\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\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\tWritableFamily,\n\tWritableHeldSelector,\n\tWritableHeldSelectorFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableSelector,\n\tWritableSelectorFamily,\n\tWritableState,\n} from \"../state-types\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Fn } from \"../utility-types\"\nimport type { Store } from \"./store\"\n\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, any, E>,\n): RegularAtom<T, E>\nexport function withdraw<T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\ttoken: MutableAtomToken<T, any>,\n): MutableAtom<T>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: AtomToken<T, any, E>,\n): Atom<T, E>\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, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, any, E>,\n): WritablePureSelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, any, E>,\n): ReadonlyPureSelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadonlySelectorToken<T, any, E>,\n): ReadonlySelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: WritableSelectorToken<T, any, E>,\n): WritableSelector<T, E>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: HeldSelectorToken<T>,\n): HeldSelector<T>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: PureSelectorToken<T, any, E>,\n): PureSelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: SelectorToken<T, any, E>,\n): Selector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: WritableToken<T, any, E>,\n): WritableState<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n): ReadableState<T, E>\n\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K, E>,\n): RegularAtomFamily<T, K, E>\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, E>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K, E>,\n): AtomFamily<T, K, E>\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, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K, E>,\n): ReadonlyPureSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K, E>,\n): WritablePureSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadonlySelectorFamilyToken<T, K, E>,\n): ReadonlySelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritableSelectorFamilyToken<T, K, E>,\n): WritableSelectorFamily<T, K, E>\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, E>(\n\tstore: Store,\n\ttoken: PureSelectorFamilyToken<T, K, E>,\n): PureSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K, E>,\n): SelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K, E>,\n): WritableFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K, E>,\n): ReadableFamily<T, K, E>\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, E>(\n\tstore: Store,\n\ttoken: WritableToken<T, any, E>,\n): WritableState<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n): ReadableState<T, E>\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 { ReadableToken, ViewOf } from \"atom.io\"\nimport { type Canonical, stringifyJson } from \"atom.io/json\"\n\nimport type { ReadableFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport function getFallback<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K, E>,\n\tfamily: ReadableFamily<T, K, E>,\n\tsubKey: NoInfer<K>,\n): ViewOf<E | 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.READONLY_VIEW\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 as ViewOf<T>\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 as ViewOf<T>\n\t\t}\n\t}\n}\n","import { writeToCache } from \"./caching\"\nimport { isFn } from \"./is-fn\"\nimport type { PureSelector, RegularAtom } from \"./state-types\"\nimport type { Store } from \"./store\"\n\nexport function safeCompute<T, E>(\n\ttarget: Store,\n\tstate: PureSelector<T, E> | RegularAtom<T, E>,\n): E | T {\n\tconst { type, key, catch: canCatch } = state\n\tswitch (type) {\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_pure_selector`: {\n\t\t\tlet val: E | T\n\t\t\ttarget.logger.info(`🧮`, type, key, `computing value`)\n\t\t\ttry {\n\t\t\t\tval = state.getFrom(target)\n\t\t\t\tif (val instanceof Promise) {\n\t\t\t\t\treturn (val as Promise<E & T>).catch((thrown) => {\n\t\t\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, thrown)\n\t\t\t\t\t\tif (canCatch) {\n\t\t\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\t\t\tif (thrown instanceof Class) {\n\t\t\t\t\t\t\t\t\treturn thrown\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\tthrow thrown\n\t\t\t\t\t}) as E | T\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, e)\n\t\t\t\tif (canCatch) {\n\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\tif (e instanceof Class) {\n\t\t\t\t\t\t\treturn writeToCache(target, state, e)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow e\n\t\t\t}\n\t\t\tconst cachedValue = writeToCache(target, state, val)\n\t\t\treturn cachedValue\n\t\t}\n\t\tcase `atom`: {\n\t\t\tlet def: E | T\n\t\t\tif (isFn(state.default)) {\n\t\t\t\ttry {\n\t\t\t\t\tdef = state.default()\n\t\t\t\t\tif (def instanceof Promise) {\n\t\t\t\t\t\tdef = (def as Promise<T> & T).catch<E | T>((thrown) => {\n\t\t\t\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, thrown)\n\t\t\t\t\t\t\tif (canCatch) {\n\t\t\t\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\t\t\t\tif (thrown instanceof Class) {\n\t\t\t\t\t\t\t\t\t\treturn thrown\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\tthrow thrown\n\t\t\t\t\t\t}) as E | T\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, e)\n\t\t\t\t\tif (canCatch) {\n\t\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\t\tif (e instanceof Class) {\n\t\t\t\t\t\t\t\tdef = writeToCache(target, state, e)\n\t\t\t\t\t\t\t\ttarget.logger.info(\n\t\t\t\t\t\t\t\t\t`✨`,\n\t\t\t\t\t\t\t\t\tstate.type,\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\t`computed default`,\n\t\t\t\t\t\t\t\t\tdef,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn def\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\tthrow e\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdef = state.default\n\t\t\t\ttarget.logger.info(`✨`, state.type, key, `using static default`, def)\n\t\t\t}\n\t\t\tconst cachedValue = writeToCache(target, state, def)\n\t\t\treturn cachedValue\n\t\t}\n\t}\n}\n","import type { ViewOf } from \"atom.io\"\n\nimport { readFromCache, writeToCache } from \"../caching\"\nimport { safeCompute } from \"../safe-compute\"\nimport type { ReadableState } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport function readOrComputeValue<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut?: undefined,\n): ViewOf<E | T>\nexport function readOrComputeValue<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut: `mut`,\n): E | T\nexport function readOrComputeValue<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut: `mut` | undefined,\n): E | T {\n\tif (target.valueMap.has(state.key)) {\n\t\treturn readFromCache(target, state, mut)\n\t}\n\ttarget.logger.info(`❔`, state.type, state.key, `value not found in cache`)\n\tconst { key } = state\n\tswitch (state.type) {\n\t\tcase `readonly_held_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\ttarget.logger.info(`🧮`, state.type, key, `computing value`)\n\t\t\treturn state.getFrom(target)\n\t\tcase `writable_pure_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `atom`:\n\t\t\treturn safeCompute(target, state)\n\t\tcase `mutable_atom`: {\n\t\t\tconst instance = new state.class()\n\t\t\ttarget.logger.info(`✨`, state.type, key, `created new instance`, instance)\n\t\t\tconst cachedValue = writeToCache(target, state, instance)\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 { Transceiver } from \"../mutable\"\nimport type {\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadonlyPureSelectorFamily,\n\tRegularAtomFamily,\n\tWritableFamily,\n\tWritablePureSelectorFamily,\n} from \"../state-types\"\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, E>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, K, E>,\n): RegularAtomFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, K, E>,\n): WritablePureSelectorFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, K, E>,\n): ReadonlyPureSelectorFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritableToken<T, K, E>,\n): WritableFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K, E>,\n): ReadableFamily<T, K, E>\n\nexport function getFamilyOfToken(\n\tstore: Store,\n\ttoken: ReadableToken<any, any, any>,\n): ReadableFamily<any, 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 type { ReadableToken, WritableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ReadableFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\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 const MUST_CREATE: unique symbol = Symbol(`MUST_CREATE`)\nexport const DO_NOT_CREATE: unique symbol = Symbol(`DO_NOT_CREATE`)\n\nexport function mintInStore<T, K extends Canonical, KK extends K, E>(\n\tmustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,\n\tstore: Store,\n\tfamily: ReadableFamily<T, K, E>,\n\tkey: KK,\n): WritableToken<T, KK, E>\nexport function mintInStore<T, K extends Canonical, KK extends K, E>(\n\tmustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,\n\tstore: Store,\n\tfamily: ReadableFamily<T, K, E>,\n\tkey: KK,\n): ReadableToken<T, KK, E>\nexport function mintInStore<T, K extends Canonical, KK extends K, E>(\n\tmustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,\n\tstore: Store,\n\tfamily: ReadableFamily<T, K, E>,\n\tkey: KK,\n): ReadableToken<T, KK, E> {\n\tconst stringKey = stringifyJson(key)\n\tconst molecule = store.molecules.get(stringKey)\n\n\tconst cannotCreate = !molecule && store.config.lifespan === `immortal`\n\n\tif (cannotCreate) {\n\t\tconst { type: familyType, key: familyKey } = family\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\tfamilyType,\n\t\t\t`\"${familyKey}\"`,\n\t\t)\n\t\tconst fullKey = `${familyKey}(${stringKey})`\n\t\tconst type = FAMILY_MEMBER_TOKEN_TYPES[familyType]\n\t\tconst stateToken: ReadableToken<T, KK, E> & { counterfeit: true } = {\n\t\t\tcounterfeit: true,\n\t\t\tkey: fullKey,\n\t\t\ttype,\n\t\t\tfamily: {\n\t\t\t\tkey: familyKey,\n\t\t\t\tsubKey: stringKey,\n\t\t\t},\n\t\t}\n\n\t\treturn stateToken\n\t}\n\n\tlet token: ReadableToken<T, KK, E>\n\tif (mustCreate === MUST_CREATE) {\n\t\tstore.logger.info(\n\t\t\t`👪`,\n\t\t\tfamily.type,\n\t\t\tfamily.key,\n\t\t\t`adds member`,\n\t\t\ttypeof key === `string` ? `\\`${key}\\`` : key,\n\t\t)\n\t\ttoken = family.create(key)\n\t\tif (molecule) {\n\t\t\tstore.moleculeData.set(stringKey, family.key)\n\t\t}\n\t} else {\n\t\tconst { type: familyType, key: familyKey } = family\n\t\tconst fullKey = `${familyKey}(${stringKey})`\n\t\tconst type = FAMILY_MEMBER_TOKEN_TYPES[familyType]\n\t\tconst stateToken: ReadableToken<T, KK, E> = {\n\t\t\tkey: fullKey,\n\t\t\ttype,\n\t\t\tfamily: {\n\t\t\t\tkey: familyKey,\n\t\t\t\tsubKey: stringKey,\n\t\t\t},\n\t\t}\n\n\t\treturn stateToken\n\t}\n\n\treturn token\n}\n","import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tStateCreationEvent,\n} 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 { newest } from \"../lineage\"\nimport type { ReadableFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { isChildStore, isRootStore } from \"../transaction\"\n\nexport function reduceReference<T, K extends Canonical, E>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<T, K, E>]\n): {\n\ttoken: ReadableToken<T, K, E>\n\tfamily: ReadableFamily<T, K, E> | undefined\n\tsubKey: NoInfer<K> | undefined\n\tisNew: boolean\n} {\n\tlet existingToken: ReadableToken<T, K, E> | undefined\n\tlet brandNewToken: ReadableToken<T, K, E> | undefined\n\tlet family: ReadableFamily<T, K, E> | undefined\n\tlet subKey: K | undefined\n\tlet token: ReadableToken<T, K, E>\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t\tif (`family` in token) {\n\t\t\tconst familyToken = getFamilyOfToken(store, token)\n\t\t\tfamily = withdraw(store, familyToken) as ReadableFamily<T, K, E>\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\tfamily,\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(MUST_CREATE, store, familyToken, subKey)\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 = withdraw(store, params[0])\n\t\tsubKey = params[1]\n\t\texistingToken = seekInStore(store, family, subKey)\n\t\tif (!existingToken) {\n\t\t\tbrandNewToken = mintInStore(MUST_CREATE, store, family, subKey)\n\t\t\ttoken = brandNewToken\n\t\t} else {\n\t\t\ttoken = existingToken\n\t\t}\n\t}\n\n\tconst isCounterfeit = `counterfeit` in token\n\tconst isNewlyCreated = Boolean(brandNewToken) && isCounterfeit === false\n\tif (isNewlyCreated && family) {\n\t\tlet subType: `readable` | `writable`\n\t\tswitch (token.type) {\n\t\t\tcase `readonly_pure_selector`:\n\t\t\tcase `readonly_held_selector`:\n\t\t\t\tsubType = `readable`\n\t\t\t\tbreak\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\tcase `writable_pure_selector`:\n\t\t\tcase `writable_held_selector`:\n\t\t\t\tsubType = `writable`\n\t\t\t\tbreak\n\t\t}\n\t\tconst stateCreationEvent: StateCreationEvent<any> = {\n\t\t\ttype: `state_creation`,\n\t\t\tsubType,\n\t\t\ttoken,\n\t\t\ttimestamp: Date.now(),\n\t\t}\n\t\tconst familySubject = family.subject as Subject<StateCreationEvent<any>>\n\t\tfamilySubject.next(stateCreationEvent)\n\t\tconst target = newest(store)\n\t\tif (token.family) {\n\t\t\tif (isRootStore(target)) {\n\t\t\t\tswitch (token.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(token)\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(token)\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(stateCreationEvent)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\ttoken,\n\t\tfamily,\n\t\tsubKey,\n\t\tisNew: Boolean(brandNewToken),\n\t}\n}\n","import type { ReadableFamilyToken, ReadableToken, ViewOf } 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, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n): E | T\n\nexport function getFromStore<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): ViewOf<E | T>\n\nexport function getFromStore<T, K extends Canonical, E>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<T, any, E>]\n): ViewOf<E | T>\n\nexport function getFromStore<T, K extends Canonical, E>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<T, any, E>]\n): ViewOf<E | T> {\n\tconst { token, family, subKey } = reduceReference(store, ...params)\n\n\tif (`counterfeit` in token && family && subKey) {\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 {\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 { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport type { ReadableState } from \"../state-types\"\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, Key> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K, E>,\n\tkey: Key,\n): RegularAtomToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K, E>,\n\tkey: Key,\n): AtomToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): WritablePureSelectorToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): SelectorToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K, E>,\n\tkey: Key,\n): WritableToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadableToken<T, Key, E> | undefined\n\nexport function seekInStore(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, any, any>,\n\tkey: Canonical,\n): ReadableToken<any, any, any> | undefined {\n\tconst subKey = stringifyJson(key)\n\tconst fullKey = `${token.key}(${subKey})`\n\tconst target = newest(store)\n\tlet state: ReadableState<any, 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 { DO_NOT_CREATE, 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, Key>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: RegularAtomFamilyToken<T, K, E>,\n\tkey: Key,\n): RegularAtomToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: AtomFamilyToken<T, K, E>,\n\tkey: Key,\n): AtomToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: WritablePureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): WritablePureSelectorToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: ReadonlyPureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: SelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): SelectorToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: WritableFamilyToken<T, K, E>,\n\tkey: Key,\n): WritableToken<T, Key, E>\n\nexport function findInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadableToken<T, Key, E>\n\nexport function findInStore(\n\tstore: Store,\n\tfamilyToken: ReadableFamilyToken<any, any, any>,\n\tkey: Canonical,\n): ReadableToken<any, any, any> {\n\tconst family = withdraw(store, familyToken)\n\tconst existingStateToken = seekInStore(store, familyToken, key)\n\tif (existingStateToken) {\n\t\treturn existingStateToken\n\t}\n\tconst newStateToken = mintInStore(DO_NOT_CREATE, store, family, key)\n\treturn newStateToken\n}\n","import type {\n\tFamilyMetadata,\n\tfindState,\n\tgetState,\n\tReadonlyPureSelectorFamilyOptions,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorOptions,\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 { getFromStore } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { createReadonlyPureSelector } from \"../selector\"\nimport type { ReadonlyPureSelectorFamily } from \"../state-types\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\nimport { findInStore } from \"./find-in-store\"\n\nexport function createReadonlyPureSelectorFamily<T, K extends Canonical, E>(\n\tstore: RootStore,\n\toptions: ReadonlyPureSelectorFamilyOptions<T, K, E>,\n\tinternalRoles?: string[],\n): ReadonlyPureSelectorFamilyToken<T, K, E> {\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, E>\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, K, E>>\n\t>()\n\n\tconst create = <Key extends K>(\n\t\tkey: Key,\n\t): ReadonlyPureSelectorToken<T, Key, E> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata<Key> = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\t\tconst individualOptions: ReadonlyPureSelectorOptions<T, E> = {\n\t\t\tkey: fullKey,\n\t\t\tget: options.get(key),\n\t\t}\n\t\tif (options.catch) {\n\t\t\tindividualOptions.catch = options.catch\n\t\t}\n\n\t\treturn createReadonlyPureSelector<T, Key, E>(\n\t\t\ttarget,\n\t\t\tindividualOptions,\n\t\t\tfamily,\n\t\t)\n\t}\n\n\tconst readonlySelectorFamily: ReadonlyPureSelectorFamily<T, K, E> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => 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}\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 { createRegularAtom } from \"../atom\"\nimport { isFn } from \"../is-fn\"\nimport { newest } from \"../lineage\"\nimport type { RegularAtomFamily } from \"../state-types\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\n\nexport function createRegularAtomFamily<T, K extends Canonical, E>(\n\tstore: RootStore,\n\toptions: RegularAtomFamilyOptions<T, K, E>,\n\tinternalRoles?: string[],\n): RegularAtomFamilyToken<T, K, E> {\n\tconst familyToken: RegularAtomFamilyToken<T, K, E> = {\n\t\tkey: options.key,\n\t\ttype: `atom_family`,\n\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`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, K, E>>>()\n\n\tconst create = <Key extends K>(key: Key): RegularAtomToken<T, Key, E> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata<Key> = { 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, E> = {\n\t\t\tkey: fullKey,\n\t\t\tdefault: isFn(def) ? () => def(key) : def,\n\t\t}\n\t\tif (options.effects) {\n\t\t\tindividualOptions.effects = options.effects(key)\n\t\t}\n\t\tif (options.catch) {\n\t\t\tindividualOptions.catch = options.catch\n\t\t}\n\n\t\treturn createRegularAtom(target, individualOptions, family)\n\t}\n\n\tconst atomFamily: RegularAtomFamily<T, K, E> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tdefault: options.default,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => createRegularAtomFamily(s, options),\n\t\tinternalRoles,\n\t}\n\n\tstore.families.set(options.key, atomFamily)\n\tif (isFn(options.default) === 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 { newest } from \"../lineage\"\nimport { createReadonlyHeldSelector } from \"../selector\"\nimport type { ReadonlyHeldSelectorFamily } from \"../state-types\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\n\nexport function createReadonlyHeldSelectorFamily<\n\tT extends object,\n\tK extends Canonical,\n>(\n\tstore: RootStore,\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 create = (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\treturn 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\t}\n\n\tconst readonlySelectorFamily: ReadonlyHeldSelectorFamily<T, K> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => createReadonlyHeldSelectorFamily(s, options),\n\t\tdefault: options.const,\n\t}\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 { newest } from \"../lineage\"\nimport { createWritableHeldSelector } from \"../selector\"\nimport type { WritableHeldSelectorFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\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 create = (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\treturn 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\t}\n\n\tconst selectorFamily: WritableHeldSelectorFamily<T, K> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => createWritableHeldSelectorFamily(s, options),\n\t\tdefault: options.const,\n\t}\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\tWritablePureSelectorOptions,\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 { getFromStore } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport { getJsonToken } from \"../mutable\"\nimport { createWritablePureSelector } from \"../selector\"\nimport type { WritablePureSelectorFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\nimport { findInStore } from \"./find-in-store\"\n\nexport function createWritablePureSelectorFamily<T, K extends Canonical, E>(\n\tstore: Store,\n\toptions: WritablePureSelectorFamilyOptions<T, K, E>,\n\tinternalRoles?: string[],\n): WritablePureSelectorFamilyToken<T, K, E> {\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, E>\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, K, E>>\n\t>()\n\n\tconst create = <Key extends K>(\n\t\tkey: Key,\n\t): WritablePureSelectorToken<T, Key, E> => {\n\t\tconst subKey = stringifyJson(key)\n\t\tconst family: FamilyMetadata<Key> = { key: familyKey, subKey }\n\t\tconst fullKey = `${familyKey}(${subKey})`\n\t\tconst target = newest(store)\n\t\tconst individualOptions: WritablePureSelectorOptions<T, E> = {\n\t\t\tkey: fullKey,\n\t\t\tget: options.get(key),\n\t\t\tset: options.set(key),\n\t\t}\n\t\tif (options.catch) {\n\t\t\tindividualOptions.catch = options.catch\n\t\t}\n\n\t\treturn createWritablePureSelector<T, Key, E>(\n\t\t\ttarget,\n\t\t\tindividualOptions,\n\t\t\tfamily,\n\t\t)\n\t}\n\n\tconst selectorFamily: WritablePureSelectorFamily<T, K, E> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tinternalRoles,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => 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}\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 { RootStore } from \"../transaction\"\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: RootStore,\n\toptions: WritableHeldSelectorFamilyOptions<T, K>,\n): WritableHeldSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T extends object, K extends Canonical>(\n\tstore: RootStore,\n\toptions: ReadonlyHeldSelectorFamilyOptions<T, K>,\n): ReadonlyHeldSelectorFamilyToken<T, K>\nexport function createSelectorFamily<T, K extends Canonical, E>(\n\tstore: RootStore,\n\toptions: WritablePureSelectorFamilyOptions<T, K, E>,\n): WritablePureSelectorFamilyToken<T, K, E>\nexport function createSelectorFamily<T, K extends Canonical, E>(\n\tstore: RootStore,\n\toptions: ReadonlyPureSelectorFamilyOptions<T, K, E>,\n): ReadonlyPureSelectorFamilyToken<T, K, E>\nexport function createSelectorFamily(\n\tstore: RootStore,\n\toptions:\n\t\t| ReadonlyHeldSelectorFamilyOptions<any, any>\n\t\t| ReadonlyPureSelectorFamilyOptions<any, any, any>\n\t\t| WritableHeldSelectorFamilyOptions<any, any>\n\t\t| WritablePureSelectorFamilyOptions<any, any, any>,\n): SelectorFamilyToken<any, 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 { 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(\n\tstore: Store,\n\ttoken: ReadableToken<any, any, any>,\n): void\n\nexport function disposeFromStore<K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, K, any>,\n\tkey: NoInfer<K>,\n): void\n\nexport function disposeFromStore<K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<any, K, any>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<any, any, any>]\n): void\n\nexport function disposeFromStore(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<any, any, any>, key: Canonical]\n\t\t| [token: ReadableToken<any, any, any>]\n): void {\n\tlet token: ReadableToken<any, any, 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 { AtomUpdateEvent, ReadableToken, StateCreationEvent } 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<\n\tR extends ReadableToken<any, any> = ReadableToken<any, any>,\n> = {\n\topen: true\n\ttoken: R\n\tdone: Set<string>\n\tprev: Map<string, any>\n\ttimestamp: number\n\tsubEvents: (AtomUpdateEvent<any> | StateCreationEvent<any>)[]\n}\n\nexport function openOperation(\n\tstore: Store,\n\ttoken: ReadableToken<any, any, 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\tsubEvents: [],\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 {\n\tAtomUpdateEvent,\n\tStateCreationEvent,\n\tStateUpdate,\n\tTimelineEvent,\n} from \"atom.io\"\n\nimport { hasRole } from \"../atom\"\nimport { readOrComputeValue } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport { isTransceiver } from \"../mutable\"\nimport type { OpenOperation } from \"../operation\"\nimport type { MutableAtom, WritableFamily, WritableState } from \"../state-types\"\nimport { deposit, type Store } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { isChildStore, isRootStore } from \"../transaction\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\n\nexport function dispatchOrDeferStateUpdate<T, E>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tstate: WritableState<T, E>,\n\t{ oldValue, newValue }: ProtoUpdate<E | T>,\n\tstateIsNewlyCreated: boolean,\n\tfamily?: WritableFamily<T, any, E>,\n): void {\n\tconst token = deposit(state)\n\tif (stateIsNewlyCreated && family) {\n\t\tstate.subject.next({ newValue })\n\t\tconst stateCreationEvent: StateCreationEvent<any> & TimelineEvent<any> = {\n\t\t\tcheckpoint: true,\n\t\t\ttype: `state_creation`,\n\t\t\tsubType: `writable`,\n\t\t\ttoken,\n\t\t\ttimestamp: Date.now(),\n\t\t\tvalue: newValue,\n\t\t}\n\t\ttarget.operation.subEvents.push(stateCreationEvent)\n\t\tconst familySubject = family.subject as Subject<StateCreationEvent<any>>\n\t\tfamilySubject.next(stateCreationEvent)\n\t\tconst innerTarget = newest(target)\n\t\tif (token.family) {\n\t\t\tif (isRootStore(innerTarget)) {\n\t\t\t\tswitch (token.type) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\ttarget.on.atomCreation.next(token)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\t\tcase `writable_held_selector`:\n\t\t\t\t\t\ttarget.on.selectorCreation.next(token)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisChildStore(innerTarget) &&\n\t\t\t\tinnerTarget.on.transactionApplying.state === null\n\t\t\t) {\n\t\t\t\tinnerTarget.transactionMeta.update.subEvents.push(stateCreationEvent)\n\t\t\t}\n\t\t}\n\t\treturn /* bailing early here to avoid redundant update */\n\t}\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.keys(),\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.keys(),\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\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<any> = {\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<any, any, any>\n\t\t\t>\n\t\t\tconst transceiver = readOrComputeValue<Transceiver<any, any, any>, never>(\n\t\t\t\ttarget,\n\t\t\t\tmutable,\n\t\t\t\t`mut`,\n\t\t\t)\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 { writeToCache } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport type { OpenOperation } from \"../operation\"\nimport { markDone } from \"../operation\"\nimport type { Atom } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\n\nexport const setAtom = <T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tatom: Atom<T, any>,\n\tnext: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n): ProtoUpdate<T> => {\n\tconst oldValue = readOrComputeValue(target, atom, `mut`)\n\tlet newValue = become(next, oldValue)\n\ttarget.logger.info(`⭐`, `atom`, atom.key, `setting value`, newValue)\n\tnewValue = writeToCache(target, atom, newValue)\n\tmarkDone(target, atom.key)\n\tevictDownstreamFromAtom(target, atom)\n\treturn { oldValue, newValue }\n}\n","import { isFn } from \"../is-fn\"\nimport type { OpenOperation } from \"../operation\"\nimport { safeCompute } from \"../safe-compute\"\nimport { traceRootSelectorAtoms } from \"../selector\"\nimport type { Atom, WritableState } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { dispatchOrDeferStateUpdate } from \"./dispatch-state-update\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\nimport { setAtom } from \"./set-atom\"\n\nfunction resetAtom<T, E>(\n\ttarget: Store & { operation: OpenOperation },\n\tatom: Atom<T, E>,\n): ProtoUpdate<E | 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: E | T\n\t\t\tif (isFn(atom.default)) def = safeCompute(target, atom)\n\t\t\telse def = atom.default\n\t\t\treturn setAtom<E | T>(target, atom, def)\n\t\t}\n\t}\n}\n\nexport function resetAtomOrSelector<T, E>(\n\ttarget: Store & { operation: OpenOperation },\n\tstate: WritableState<T, E>,\n): ProtoUpdate<E | T> {\n\tlet protoUpdate: ProtoUpdate<E | 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_held_selector`:\n\t\t\t{\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 value = state.getFrom(target)\n\t\t\t\tprotoUpdate = { oldValue: value, newValue: value }\n\t\t\t}\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\t\t{\n\t\t\t\tconst oldValue = safeCompute(target, state)\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 = safeCompute(target, state)\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 { Setter, 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, TT extends T>(\n\tstore: Store,\n\ttoken: WritableToken<T, any, any>,\n\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n): void\n\nexport function setIntoStore<T, TT extends T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n): void\n\nexport function setIntoStore<T, TT extends T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, K, any>,\n\t\t\t\tkey: NoInfer<K>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T, any, any>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n): void\n\nexport function setIntoStore<T, TT extends T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, K, any>,\n\t\t\t\tkey: NoInfer<K>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T, any, any>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n): void {\n\toperateOnStore(OWN_OP, store, ...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(\n\tstore: Store,\n\ttoken: WritableToken<any, any, any>,\n): void\n\nexport function resetInStore<K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<any, K, any>,\n\tkey: NoInfer<K>,\n): void\n\nexport function resetInStore<T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]\n\t\t| [token: WritableToken<T, any, any>]\n): void\n\nexport function resetInStore<T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]\n\t\t| [token: WritableToken<T, any, any>]\n): void {\n\tconst subParams = [...params, RESET_STATE] as const\n\tsetIntoStore(store, ...subParams)\n}\n","import { writeToCache } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state\"\nimport { markDone, type OpenOperation } from \"../operation\"\nimport type { WritableSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\n\nexport function setSelector<T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tselector: WritableSelector<T, any>,\n\tnext: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n): ProtoUpdate<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 = readOrComputeValue(target, selector, `mut`)\n\t\t\tnewValue = become(next, oldValue)\n\t\t\tnewValue = writeToCache(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 { OpenOperation } from \"../operation\"\nimport type { WritableState } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport type { ProtoUpdate } from \"./operate-on-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, any>,\n\tvalue: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n): ProtoUpdate<T> => {\n\tlet protoUpdate: ProtoUpdate<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 { Setter, 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 { WritableFamily } from \"../state-types\"\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 type ProtoUpdate<T> = { oldValue: T; newValue: T }\n\nexport const OWN_OP: unique symbol = Symbol(`OWN_OP`)\nexport const JOIN_OP: unique symbol = Symbol(`JOIN_OP`)\n\nexport function operateOnStore<T, TT extends T, K extends Canonical, E>(\n\topMode: typeof JOIN_OP | typeof OWN_OP,\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, K, E>,\n\t\t\t\tkey: NoInfer<K>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T, any, E>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n): void {\n\tlet existingToken: WritableToken<T, K, E> | undefined\n\tlet brandNewToken: WritableToken<T, K, E> | undefined\n\tlet token: WritableToken<T, K, E>\n\tlet family: WritableFamily<T, K, E> | undefined\n\tlet key: K | null\n\tlet value: Setter<TT> | TT | typeof RESET_STATE\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\ttoken = brandNewToken = mintInStore(MUST_CREATE, store, family, key)\n\t\t\t} else {\n\t\t\t\ttoken = existingToken\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfamily = withdraw(store, 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\ttoken = brandNewToken = mintInStore(MUST_CREATE, store, family, key)\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(opMode, store, 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: ProtoUpdate<E | 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\n\tconst isNewlyCreated = Boolean(brandNewToken)\n\tdispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated, family)\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 { isAtomKey } from \"../keys\"\nimport type { Atom } from \"../state-types\"\nimport type { Store } from \"../store\"\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<any, any>> {\n\tconst dependencies = getSelectorDependencyKeys(store, selectorKey)\n\n\tconst roots = new Map<string, Atom<unknown, 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, 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, any, 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, any>, Canonical]\n\t\t\t\t| [ReadableToken<any, any, any>]\n\t\t) => {\n\t\t\tconst target = newest(store)\n\t\t\tconst { token, family, subKey } = reduceReference(store, ...params)\n\t\t\tlet dependencyValue: unknown\n\t\t\tif (`counterfeit` in token && family && subKey) {\n\t\t\t\tdependencyValue = getFallback(store, token, family, 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>(\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: NoInfer<K>,\n\t\t\t\t\t\tvalue: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n\t\t\t\t ]\n\t\t\t\t| [\n\t\t\t\t\t\ttoken: WritableToken<T>,\n\t\t\t\t\t\tvalue: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n\t\t\t\t ]\n\t\t) => {\n\t\t\tconst target = newest(store)\n\t\t\toperateOnStore(JOIN_OP, target, ...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 { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { ReadonlyHeldSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\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\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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\tstore.logger.info(`✨`, type, key, `=`, 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: RootStore) => createReadonlyHeldSelector(s, options, family),\n\t}\n\tif (family) readonlySelector.family = family\n\n\ttarget.readonlySelectors.set(key, readonlySelector)\n\tconst token: ReadonlyHeldSelectorToken<T> = { key, type }\n\tif (family) token.family = family\n\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlyPureSelectorOptions,\n\tReadonlyPureSelectorToken,\n\tStateUpdate,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { ReadonlyPureSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function createReadonlyPureSelector<T, K extends Canonical, E>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorOptions<T, E>,\n\tfamily: FamilyMetadata<K> | undefined,\n): ReadonlyPureSelectorToken<T, K, E> {\n\tconst target = newest(store)\n\tconst subject = new Subject<StateUpdate<E | T>>()\n\tconst covered = new Set<string>()\n\tconst key = options.key\n\tconst type = `readonly_pure_selector` as const\n\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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, E> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tgetFrom,\n\t\tinstall: (s: RootStore) => createReadonlyPureSelector(s, options, family),\n\t}\n\tif (family) readonlySelector.family = family\n\n\ttarget.readonlySelectors.set(key, readonlySelector)\n\n\tconst token: ReadonlyPureSelectorToken<T> = { key, type }\n\tif (family) token.family = family\n\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tWritableHeldSelectorOptions,\n\tWritableHeldSelectorToken,\n} from \"atom.io\"\n\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { WritableHeldSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\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\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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: RootStore) => createWritableHeldSelector(s, options, family),\n\t}\n\tif (family) mySelector.family = family\n\n\ttarget.writableSelectors.set(key, mySelector)\n\n\tconst token: WritableHeldSelectorToken<T> = { key, type }\n\tif (family) token.family = family\n\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tStateUpdate,\n\tWritablePureSelectorOptions,\n\tWritablePureSelectorToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { writeToCache } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { WritablePureSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\nimport { registerSelector } from \"./register-selector\"\n\nexport function createWritablePureSelector<T, K extends Canonical, E>(\n\tstore: Store,\n\toptions: WritablePureSelectorOptions<T, E>,\n\tfamily: FamilyMetadata<K> | undefined,\n): WritablePureSelectorToken<T, K, E> {\n\tconst target = newest(store)\n\tconst subject = new Subject<StateUpdate<E | T>>()\n\tconst covered = new Set<string>()\n\tconst key = options.key\n\tconst type = `writable_pure_selector` as const\n\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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): E | 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, E> = {\n\t\t...options,\n\t\ttype,\n\t\tsubject,\n\t\tgetFrom,\n\t\tsetSelf,\n\t\tinstall: (s: RootStore) => createWritablePureSelector(s, options, family),\n\t}\n\tif (family) mySelector.family = family\n\n\ttarget.writableSelectors.set(key, mySelector)\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, E>(\n\tstore: Store,\n\toptions: WritablePureSelectorOptions<T, E>,\n): WritablePureSelectorToken<T, any, E>\nexport function createStandaloneSelector<T, E>(\n\tstore: Store,\n\toptions: ReadonlyPureSelectorOptions<T, E>,\n): ReadonlyPureSelectorToken<T, any, E>\nexport function createStandaloneSelector(\n\tstore: Store,\n\toptions:\n\t\t| ReadonlyHeldSelectorOptions<any>\n\t\t| ReadonlyPureSelectorOptions<any, any>\n\t\t| WritableHeldSelectorOptions<any>\n\t\t| WritablePureSelectorOptions<any, any>,\n):\n\t| ReadonlyHeldSelectorToken<any>\n\t| ReadonlyPureSelectorToken<any, any, any>\n\t| WritableHeldSelectorToken<any>\n\t| WritablePureSelectorToken<any, any, 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 { newest } from \"../lineage\"\nimport { type Store, withdraw } from \"../store\"\nimport { isChildStore } from \"../transaction\"\n\nexport function disposeSelector(\n\tstore: Store,\n\tselectorToken: SelectorToken<unknown, any, any>,\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, 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 { newest } from \"../lineage\"\nimport type { ReadableState } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport const recallState = <T, E>(\n\tstore: Store,\n\tstate: ReadableState<T, E>,\n): 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 { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport type { Atom, Selector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { recallState } from \"./recall-state\"\n\nexport const subscribeToRootDependency = (\n\ttarget: Store,\n\tselector: Selector<any, any>,\n\tatom: Atom<any, 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","import type { ReadableToken, StateUpdate, UpdateHandler } from \"atom.io\"\n\nimport { hasRole } from \"../atom\"\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, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n\tkey: string,\n\thandleUpdate: UpdateHandler<E | T>,\n): () => void {\n\tfunction safelyHandleUpdate(update: StateUpdate<any>): void {\n\t\tif (store.operation.open) {\n\t\t\tif (\n\t\t\t\tstate?.type === `atom` &&\n\t\t\t\thasRole(state, `tracker:signal`) &&\n\t\t\t\t`*` + store.operation.token.key === token.key &&\n\t\t\t\t`inboundTracker` in handleUpdate\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\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<E | 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 { 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 { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Fn } from \"../utility-types\"\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 {\n\tFamilyMetadata,\n\tMutableAtomToken,\n\tRegularAtomToken,\n\tStateUpdate,\n} from \"atom.io\"\n\nimport { createRegularAtom } from \"../atom\"\nimport { getFromStore } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport { setIntoStore } from \"../set-state\"\nimport { JOIN_OP, operateOnStore } from \"../set-state/operate-on-store\"\nimport type { Store } from \"../store\"\nimport { subscribeToState, subscribeToTimeline } from \"../subscribe\"\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<\n\t\t\tSignalFrom<T> | null,\n\t\t\tany,\n\t\t\tnever\n\t\t>(\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-from-core:${storeName}:${storeStatus}:${stateKey}`\n\t\tconst trackerCapturesOutboundSignal = (update: SignalFrom<T>) => {\n\t\t\toperateOnStore(JOIN_OP, 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 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-to-core:${storeName}:${storeStatus}:${stateKey}`\n\t\tsubscribeToState(\n\t\t\ttarget,\n\t\t\tlatestSignalState,\n\t\t\tsubscriptionKey,\n\t\t\tObject.assign(\n\t\t\t\tfunction trackerCapturesInboundSignal({\n\t\t\t\t\tnewValue,\n\t\t\t\t\toldValue,\n\t\t\t\t}: StateUpdate<SignalFrom<T> | null>) {\n\t\t\t\t\tconst timelineId = target.timelineTopics.getRelatedKey(\n\t\t\t\t\t\tlatestSignalState.key,\n\t\t\t\t\t)\n\n\t\t\t\t\tif (timelineId && target.timelines.get(timelineId)?.timeTraveling) {\n\t\t\t\t\t\tconst unsubscribe = subscribeToTimeline(\n\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t{ key: timelineId, type: `timeline` },\n\t\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\t\tfunction trackerWaitsForTimeTravelToFinish(update) {\n\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\tsetIntoStore(target, mutableState, (transceiver) => {\n\t\t\t\t\t\t\t\t\tif (update === `redo` && newValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.do(newValue)\n\t\t\t\t\t\t\t\t\t} else if (update === `undo` && oldValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.undo(oldValue)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn transceiver\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// const mutable = getFromStore(target, mutableState)\n\t\t\t\t\t// const updateNumber = mutable.getUpdateNumber(newValue)\n\t\t\t\t\t// const eventOffset = updateNumber - mutable.cacheUpdateNumber\n\t\t\t\t\t// if (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\t// } else {\n\t\t\t\t\t// \tconst expected = mutable.cacheUpdateNumber + 1\n\t\t\t\t\t// \ttarget.logger.info(\n\t\t\t\t\t// \t\t`❌`,\n\t\t\t\t\t// \t\t`mutable_atom`,\n\t\t\t\t\t// \t\tmutableState.key,\n\t\t\t\t\t// \t\t`could not be updated. Expected update number`,\n\t\t\t\t\t// \t\texpected,\n\t\t\t\t\t// \t\t`but got`,\n\t\t\t\t\t// \t\tupdateNumber,\n\t\t\t\t\t// \t)\n\t\t\t\t\t// }\n\t\t\t\t},\n\t\t\t\t{ inboundTracker: true },\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 { newest } from \"../lineage\"\nimport { createStandaloneSelector } from \"../selector\"\nimport { resetInStore, setIntoStore } from \"../set-state\"\nimport type { MutableAtom } from \"../state-types\"\nimport { deposit, type Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport type { RootStore } from \"../transaction\"\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: RootStore) => {\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 { createRegularAtomFamily } from \"../families\"\nimport type { MutableAtomFamily, RegularAtomFamily } from \"../state-types\"\nimport { withdraw } from \"../store\"\nimport type { RootStore } from \"../transaction\"\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: RootStore) {\n\t\tconst latestSignalAtoms = createRegularAtomFamily<\n\t\t\tSignalFrom<T> | null,\n\t\t\tK,\n\t\t\tnever\n\t\t>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `*${mutableAtoms.key}`,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\t[`mutable`, `updates`],\n\t\t)\n\t\tthis.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 } from \"../families\"\nimport { newest } from \"../lineage\"\nimport { createMutableAtom } from \"../mutable\"\nimport type { MutableAtomFamily } from \"../state-types\"\nimport { Subject } from \"../subject\"\nimport type { RootStore } from \"../transaction\"\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: RootStore,\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 create = (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\treturn createMutableAtom(target, individualOptions, family)\n\t}\n\n\tconst atomFamily: MutableAtomFamily<T, K> = {\n\t\t...familyToken,\n\t\tcreate,\n\t\tclass: options.class,\n\t\tsubject,\n\t\tinstall: (s: RootStore) => createMutableAtomFamily(s, options),\n\t\tinternalRoles,\n\t}\n\n\tstore.families.set(options.key, atomFamily)\n\n\tcreateWritablePureSelectorFamily<AsJSON<T>, K, never>(\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 { newest } from \"../lineage\"\nimport type { WritablePureSelectorFamily } from \"../state-types\"\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, never> => {\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\tnever\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 { newest } from \"../lineage\"\nimport type { RegularAtomFamily } from \"../state-types\"\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): RegularAtomFamily<SignalFrom<T>, K, never> => {\n\tconst target = newest(store)\n\tconst key = `*${mutableAtomFamily.key}`\n\tconst updateFamily = target.families.get(key) as RegularAtomFamily<\n\t\tSignalFrom<T>,\n\t\tK,\n\t\tnever\n\t>\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 extends { subscribe: (key: string, fn: (update: S) => void) => () => void },\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\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`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 { Future } from \"./future\"\nimport { Tracker, type Transceiver } from \"./mutable\"\nimport { closeOperation, openOperation } from \"./operation\"\nimport {\n\tevictDownstreamFromAtom,\n\tevictDownstreamFromSelector,\n} from \"./set-state/evict-downstream\"\nimport type { ReadableState } from \"./state-types\"\nimport type { Store } from \"./store\"\nimport { isChildStore } from \"./transaction\"\n\nexport function writeToCache<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tvalue: E | T,\n): E | T\nexport function writeToCache<T extends Promise<any>, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tvalue: T,\n): Future<Awaited<E | T>>\nexport function writeToCache<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tvalue: E | T,\n): E | Future<E | 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\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 definition, 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.type, key, `rejected:`, thrown)\n\t\t\t})\n\t\treturn future\n\t}\n\ttarget.logger.info(`📝`, state.type, state.key, `writing to cache`, value)\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, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut: `mut` | undefined,\n): E | T {\n\ttarget.logger.info(`📖`, state.type, state.key, `reading cached value`)\n\tlet value = target.valueMap.get(state.key) as E | 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 { evictCachedValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Atom } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport function evictDownstreamFromAtom(\n\tstore: Store,\n\tatom: Atom<any, any>,\n): 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 {\n\tFamilyMetadata,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport { resetInStore, setIntoStore } from \"../set-state\"\nimport type { RegularAtom } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport type { RootStore } from \"../transaction\"\nimport type { InternalRole } from \"./has-role\"\n\nexport function createRegularAtom<T, K extends Canonical, E>(\n\tstore: Store,\n\toptions: RegularAtomOptions<T, E>,\n\tfamily: FamilyMetadata<K> | undefined,\n\tinternalRoles?: InternalRole[],\n): RegularAtomToken<T, K, E> {\n\tconst type = `atom`\n\tconst { key } = options\n\tstore.logger.info(`🔨`, type, key, `is being created`)\n\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) as RegularAtomToken<T, K, E>\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: RegularAtom<T, E> = {\n\t\t...options,\n\t\ttype,\n\t\tinstall: (s: RootStore) => {\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) as RegularAtomToken<T, K, E>\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 { Atom } from \"../state-types\"\n\nexport const INTERNAL_ROLES = [`tracker:signal`] as const\nexport type InternalRole = (typeof INTERNAL_ROLES)[number]\n\nexport function hasRole(atom: Atom<any, 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","import type { AtomDisposalEvent, AtomToken, StateLifecycleEvent } from \"atom.io\"\n\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { newest } from \"../lineage\"\nimport { getUpdateToken } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { isChildStore } from \"../transaction\"\nimport { hasRole } from \"./has-role\"\n\nexport function disposeAtom(\n\tstore: Store,\n\tatomToken: AtomToken<any, any, any>,\n): 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, any, any>>\n\t\t>\n\n\t\tconst disposalEvent: AtomDisposalEvent<AtomToken<any, any, 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(disposalEvent)\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\t\t\tconst isTracker = hasRole(atom, `tracker:signal`)\n\t\t\tif (!updateAlreadyCaptured && !isTracker) {\n\t\t\t\ttarget.transactionMeta.update.subEvents.push(disposalEvent)\n\t\t\t}\n\t\t} else {\n\t\t\tstore.on.atomDisposal.next(atomToken)\n\t\t}\n\t}\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 type { RootStore } from \"./transaction\"\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: RootStore,\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\tfindState,\n\tgetState,\n\tJoinOptions,\n\tMutableAtomFamilyToken,\n\tReadonlyPureSelectorFamilyToken,\n\tsetState,\n\tWrite,\n\tWriterToolkit,\n} from \"atom.io\"\nimport { Anarchy } from \"atom.io\"\nimport { stringifyJson } from \"atom.io/json\"\nimport { UList } from \"atom.io/transceivers/u-list\"\n\nimport { capitalize } from \"../capitalize\"\nimport { createReadonlyPureSelectorFamily, findInStore } from \"../families\"\nimport { getFromStore } from \"../get-state\"\nimport type { BaseExternalStoreConfiguration } from \"../junction\"\nimport { Junction } from \"../junction\"\nimport { createMutableAtomFamily, getJsonFamily, getJsonToken } from \"../mutable\"\nimport { JOIN_OP, operateOnStore, setIntoStore } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport type { RootStore } from \"../transaction\"\n\nexport type JoinStateFamilies<\n\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n> = Cardinality extends `1:1`\n\t? {\n\t\t\treadonly [N in AName as `${N}KeyOf${Capitalize<BName>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\tA | null,\n\t\t\t\tB\n\t\t\t>\n\t\t} & {\n\t\t\treadonly [N in BName as `${N}KeyOf${Capitalize<AName>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\tB | null,\n\t\t\t\tA\n\t\t\t>\n\t\t}\n\t: Cardinality extends `1:n`\n\t\t? {\n\t\t\t\treadonly [N in BName as `${N}KeysOf${Capitalize<AName>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\tB[],\n\t\t\t\t\tA\n\t\t\t\t>\n\t\t\t}\n\t\t: Cardinality extends `n:n`\n\t\t\t? {\n\t\t\t\t\treadonly [N in AName as `${N}KeysOf${Capitalize<BName>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\tA[],\n\t\t\t\t\t\tB\n\t\t\t\t\t>\n\t\t\t\t} & {\n\t\t\t\t\treadonly [N in BName as `${N}KeysOf${Capitalize<AName>}`]: ReadonlyPureSelectorFamilyToken<\n\t\t\t\t\t\tB[],\n\t\t\t\t\t\tA\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t: never\n\nexport class Join<\n\tconst AName extends string,\n\tconst A extends string,\n\tconst BName extends string,\n\tconst B extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n> {\n\tprivate toolkit: WriterToolkit\n\tpublic options: JoinOptions<AName, A, BName, B, Cardinality>\n\tpublic relations: Junction<AName, A, BName, B>\n\tpublic states: JoinStateFamilies<AName, A, BName, B, Cardinality>\n\tpublic relatedKeysAtoms: MutableAtomFamilyToken<UList<string>, string>\n\n\tpublic transact(\n\t\ttoolkit: WriterToolkit,\n\t\trun: (join: Join<AName, A, BName, B, Cardinality>) => 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<AName, A, BName, B, Cardinality>,\n\t\tstore: RootStore = IMPLICIT.STORE,\n\t) {\n\t\ttype AB = A & B\n\n\t\tthis.store = store\n\t\tthis.realm = new Anarchy(store)\n\t\tthis.options = options\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: AName = options.between[0]\n\t\tconst bSide: BName = options.between[1]\n\t\tconst relatedKeysAtoms = createMutableAtomFamily<UList<string>, string>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tclass: UList,\n\t\t\t},\n\t\t\t[`join`, `relations`],\n\t\t)\n\t\tthis.relatedKeysAtoms = relatedKeysAtoms\n\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\t// relationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\trelationsOfA.clear()\n\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\tconst relationsOfBAtom = find(relatedKeysAtoms, newRelationB)\n\t\t\t\t\tconst relationsOfB = get(relationsOfBAtom)\n\t\t\t\t\tconst newRelationBIsAlreadyRelated = relationsOfB.has(a as AB)\n\t\t\t\t\tif (this.relations.cardinality === `1:n`) {\n\t\t\t\t\t\tconst previousOwnersToDispose: string[] = []\n\t\t\t\t\t\tfor (const previousOwner of relationsOfB) {\n\t\t\t\t\t\t\tif (previousOwner === a) {\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlet previousOwnerSize: number | undefined\n\t\t\t\t\t\t\toperateOnStore(\n\t\t\t\t\t\t\t\tJOIN_OP,\n\t\t\t\t\t\t\t\tthis.store,\n\t\t\t\t\t\t\t\trelatedKeysAtoms,\n\t\t\t\t\t\t\t\tpreviousOwner,\n\t\t\t\t\t\t\t\t(relations) => {\n\t\t\t\t\t\t\t\t\trelations.delete(newRelationB as AB)\n\t\t\t\t\t\t\t\t\tpreviousOwnerSize = relations.size\n\t\t\t\t\t\t\t\t\treturn relations\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 (previousOwnerSize === 0) {\n\t\t\t\t\t\t\t\tpreviousOwnersToDispose.push(previousOwner)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!newRelationBIsAlreadyRelated && relationsOfB.size > 0) {\n\t\t\t\t\t\t\tset(relationsOfBAtom, (relations) => {\n\t\t\t\t\t\t\t\trelations.clear()\n\t\t\t\t\t\t\t\treturn relations\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (const previousOwner of previousOwnersToDispose) {\n\t\t\t\t\t\t\tconst [x, y] = [newRelationB, previousOwner].sort()\n\t\t\t\t\t\t\tconst compositeKey = `${x}:${y}`\n\t\t\t\t\t\t\tstore.moleculeJoins.delete(compositeKey)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!newRelationBIsAlreadyRelated) {\n\t\t\t\t\t\tset(relationsOfBAtom, (relations) => {\n\t\t\t\t\t\t\trelations.add(a as AB)\n\t\t\t\t\t\t\treturn relations\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\trelationsOfA.add(newRelationB)\n\t\t\t\t}\n\t\t\t\t// return 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\t// relationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\trelationsOfA.add(newRelationB)\n\t\t\t\t}\n\t\t\t\t// return 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 baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\t\tgetRelatedKeys: (key) =>\n\t\t\t\tthis.toolkit.get(relatedKeysAtoms, key) as UList<A> | UList<B>,\n\t\t\taddRelation: (a, b) => {\n\t\t\t\tthis.store.moleculeJoins.set(`\"${a}\"`, options.key)\n\t\t\t\tthis.store.moleculeJoins.set(`\"${b}\"`, options.key)\n\t\t\t\tif (!this.store.molecules.has(stringifyJson(a))) {\n\t\t\t\t\tthis.realm.allocate(options.key, a)\n\t\t\t\t}\n\t\t\t\tif (!this.store.molecules.has(stringifyJson(b))) {\n\t\t\t\t\tthis.realm.allocate(options.key, b)\n\t\t\t\t}\n\t\t\t\tthis.toolkit.set(relatedKeysAtoms, a, (aKeys) => aKeys.add(b))\n\t\t\t\tthis.toolkit.set(relatedKeysAtoms, b, (bKeys) => bKeys.add(a))\n\t\t\t},\n\t\t\tdeleteRelation: (a, b) => {\n\t\t\t\tthis.toolkit.set(relatedKeysAtoms, a, (aKeys) => {\n\t\t\t\t\taKeys.delete(b)\n\t\t\t\t\treturn aKeys\n\t\t\t\t})\n\t\t\t\tthis.toolkit.set(relatedKeysAtoms, b, (bKeys) => {\n\t\t\t\t\tbKeys.delete(a)\n\t\t\t\t\treturn bKeys\n\t\t\t\t})\n\t\t\t\tconst [x, y] = [a, b].sort()\n\t\t\t\tconst compositeKey = `${x}:${y}`\n\t\t\t\tthis.store.moleculeJoins.delete(compositeKey)\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) => {\n\t\t\t\tconst aKeys = this.toolkit.get(relatedKeysAtoms, a)\n\t\t\t\treturn b ? aKeys.has(b as AB) : aKeys.size > 0\n\t\t\t},\n\t\t}\n\t\tconst externalStore = baseExternalStoreConfiguration\n\t\tconst relations = new Junction<AName, A, BName, B>(options as any, {\n\t\t\texternalStore,\n\t\t\tisAType: options.isAType,\n\t\t\tisBType: options.isBType,\n\t\t\t// makeContentKey: (...args) => {\n\t\t\t// \tconst [a, b] = args\n\t\t\t// \tconst [x, y] = args.sort()\n\t\t\t// \tconst compositeKey = `${x}:${y}`\n\t\t\t// \tconst aMolecule = store.molecules.get(stringifyJson(a))\n\t\t\t// \tconst bMolecule = store.molecules.get(stringifyJson(b))\n\t\t\t// \tif (!aMolecule) {\n\t\t\t// \t\tthis.realm.allocate(options.key, a)\n\t\t\t// \t}\n\t\t\t// \tif (!bMolecule) {\n\t\t\t// \t\tthis.realm.allocate(options.key, b)\n\t\t\t// \t}\n\n\t\t\t// \tthis.realm.allocate(a, compositeKey, `all`)\n\t\t\t// \tthis.realm.claim(b, compositeKey)\n\t\t\t// \tthis.store.moleculeJoins.set(compositeKey, options.key)\n\t\t\t// \treturn compositeKey\n\t\t\t// },\n\t\t})\n\n\t\tconst createSingleKeySelectorFamily = () =>\n\t\t\tcreateReadonlyPureSelectorFamily<string | null, string, never>(\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<readonly string[], string, never>(\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\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\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\tthis.relations = relations\n\t\t\t\tthis.states = {\n\t\t\t\t\t[stateKeyA]: singleRelatedKeySelectors,\n\t\t\t\t\t[stateKeyB]: singleRelatedKeySelectors,\n\t\t\t\t} as JoinStateFamilies<AName, A, BName, B, Cardinality>\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<AName, A, BName, B, Cardinality>\n\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.states = baseStates\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\tthis.relations = relations\n\t\t\t\tthis.states = {\n\t\t\t\t\t[stateKeyA]: multipleRelatedKeysSelectors,\n\t\t\t\t\t[stateKeyB]: multipleRelatedKeysSelectors,\n\t\t\t\t} as JoinStateFamilies<AName, A, BName, B, Cardinality>\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { JoinOptions, JoinToken } from \"atom.io\"\n\nimport type { RootStore } from \"../transaction\"\nimport { Join } from \"./join-internal\"\n\nexport function createJoin<\n\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n>(\n\tstore: RootStore,\n\toptions: JoinOptions<AName, A, BName, B, Cardinality>,\n): JoinToken<AName, A, BName, B, Cardinality> {\n\tstore.joins.set(options.key, new Join(options))\n\tconst token: JoinToken<AName, A, BName, B, Cardinality> = {\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\"\n\nimport { eldest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport { Join } from \"./join-internal\"\n\nexport function getJoin<\n\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n>(\n\ttoken: JoinToken<AName, A, BName, B, Cardinality>,\n\tstore: Store,\n): Join<AName, A, BName, B, Cardinality> {\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\tconst root = eldest(store)\n\t\tmyJoin = new Join(rootJoin.options, root)\n\t\tstore.joins.set(token.key, myJoin)\n\t}\n\treturn myJoin\n}\n","import type { JoinToken } from \"atom.io\"\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\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n>(\n\ttoken: JoinToken<AName, A, BName, B, Cardinality>,\n\tchange: (relations: Junction<AName, A, BName, B>) => 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\"\n\nimport { capitalize } from \"../capitalize\"\nimport { findInStore } from \"../families\"\nimport type { RootStore } from \"../transaction\"\nimport { getJoin } from \"./get-join\"\n\nexport function findRelationsInStore<\n\tAName extends string,\n\tA extends string,\n\tBName extends string,\n\tB extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n>(\n\ttoken: JoinToken<AName, A, BName, B, Cardinality>,\n\tkey: A | B,\n\tstore: RootStore,\n): JoinStates<AName, A, BName, B, Cardinality> {\n\tconst myJoin = getJoin(token, store)\n\tlet relations: JoinStates<AName, A, BName, B, Cardinality>\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<AName, A, BName, B, Cardinality>\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<AName, A, BName, B, Cardinality>\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<AName, A, BName, B, Cardinality>\n\t\t}\n\t}\n\treturn relations\n}\n","import type { JoinToken, MutableAtomFamilyToken } from \"atom.io\"\nimport type { UList } from \"atom.io/transceivers/u-list\"\n\nimport type { RootStore } from \"../transaction\"\nimport { getJoin } from \"./get-join\"\n\nexport function getInternalRelationsFromStore<\n\tAName extends string,\n\tBName extends string,\n>(\n\ttoken: JoinToken<any, AName, any, BName, any>,\n\tstore: RootStore,\n): MutableAtomFamilyToken<UList<AName> | UList<BName>, string> {\n\tconst myJoin = getJoin(token, store)\n\tconst family = myJoin.relatedKeysAtoms as MutableAtomFamilyToken<\n\t\tUList<AName> | UList<BName>,\n\t\tstring\n\t>\n\treturn family\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tAtomUpdateEvent,\n\tStateCreationEvent,\n\tStateDisposalEvent,\n\tStateUpdate,\n\tTimelineEvent,\n\tTimelineManageable,\n\tTimelineOptions,\n\tTimelineSelectorUpdateEvent,\n\tTimelineToken,\n\tTransactionOutcomeEvent,\n\tTransactionSubEvent,\n\tTransactionToken,\n\tWritablePureSelectorToken,\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 type { RootStore } from \"../transaction\"\nimport { isChildStore } from \"../transaction\"\n\nexport type Timeline<ManagedAtom extends TimelineManageable> = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineEvent<ManagedAtom>[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: RootStore) => void\n\tsubject: Subject<TimelineEvent<ManagedAtom> | `redo` | `undo`>\n\tsubscriptions: Map<string, () => void>\n}\n\nexport function createTimeline<ManagedAtom extends TimelineManageable>(\n\tstore: RootStore,\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\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\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<any, any, any> = 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, 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, any, 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\tbuildSelectorUpdate(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\ttl,\n\t\t\t\t\t\t\tatomToken,\n\t\t\t\t\t\t\tupdate,\n\t\t\t\t\t\t\tcurrentSelectorToken,\n\t\t\t\t\t\t\tcurrentSelectorTime,\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\n\t\t\t\t\t\tconst atomUpdate: AtomUpdateEvent<any> & TimelineEvent<any> = {\n\t\t\t\t\t\t\tcheckpoint: true,\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\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\taddToHistory(tl, atomUpdate)\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, 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\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: TimelineEvent<any> &\n\t\t\t\t\t\tTransactionOutcomeEvent<TransactionToken<any>> = {\n\t\t\t\t\t\tcheckpoint: true,\n\t\t\t\t\t\t...transactionUpdate,\n\t\t\t\t\t\tsubEvents: subEventsFiltered,\n\t\t\t\t\t}\n\n\t\t\t\t\taddToHistory(tl, timelineTransactionUpdate)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n}\n\nfunction buildSelectorUpdate(\n\tstore: Store,\n\ttl: Timeline<any>,\n\tatomToken: AtomToken<any, any, any>,\n\teventOrUpdate: StateCreationEvent<any> | StateUpdate<any>,\n\tcurrentSelectorToken: WritablePureSelectorToken<any>,\n\tcurrentSelectorTime: number,\n) {\n\tlet latestUpdate: TimelineEvent<any> | undefined = tl.history.at(-1)\n\tif (currentSelectorTime !== tl.selectorTime) {\n\t\tconst selectorUpdate: TimelineEvent<any> & TimelineSelectorUpdateEvent<any> =\n\t\t\t(latestUpdate = {\n\t\t\t\tcheckpoint: true,\n\t\t\t\ttype: `selector_update`,\n\t\t\t\ttimestamp: currentSelectorTime,\n\t\t\t\ttoken: currentSelectorToken,\n\t\t\t\tsubEvents: [],\n\t\t\t})\n\t\tif (`type` in eventOrUpdate) {\n\t\t\tlatestUpdate.subEvents.push(eventOrUpdate)\n\t\t} else {\n\t\t\tlatestUpdate.subEvents.push({\n\t\t\t\ttype: `atom_update`,\n\t\t\t\ttoken: atomToken,\n\t\t\t\tupdate: eventOrUpdate,\n\t\t\t\ttimestamp: Date.now(), // 👺 use store operation\n\t\t\t})\n\t\t}\n\n\t\taddToHistory(tl, latestUpdate)\n\t\ttl.selectorTime = currentSelectorTime\n\n\t\tstore.logger.info(\n\t\t\t`⌛`,\n\t\t\t`timeline`,\n\t\t\ttl.key,\n\t\t\t`got a selector_update \"${currentSelectorToken.key}\" with`,\n\t\t\tlatestUpdate.subEvents.map((event) => event.token.key),\n\t\t)\n\n\t\tconst operation = store.operation\n\t\tconst unsub = store.on.operationClose.subscribe(\n\t\t\t`timeline:${tl.key} (needs to gather nested selector creations)`,\n\t\t\t() => {\n\t\t\t\tunsub()\n\t\t\t\tif (operation.open) {\n\t\t\t\t\tselectorUpdate.subEvents = [\n\t\t\t\t\t\t...operation.subEvents,\n\t\t\t\t\t\t...selectorUpdate.subEvents,\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t} else {\n\t\tif (latestUpdate?.type === `selector_update`) {\n\t\t\tif (`type` in eventOrUpdate) {\n\t\t\t\tlatestUpdate.subEvents.push(eventOrUpdate)\n\t\t\t} else {\n\t\t\t\tlatestUpdate.subEvents.push({\n\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\ttoken: atomToken,\n\t\t\t\t\tupdate: eventOrUpdate,\n\t\t\t\t\ttimestamp: Date.now(), // 👺 use store operation\n\t\t\t\t})\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⌛`,\n\t\t\t\t`timeline`,\n\t\t\t\ttl.key,\n\t\t\t\t`set selector_update \"${currentSelectorToken.key}\" to`,\n\t\t\t\tlatestUpdate?.subEvents.map((event) => event.token.key),\n\t\t\t)\n\t\t}\n\t}\n\tif (latestUpdate) {\n\t\ttl.subject.next(latestUpdate)\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\tconst currentSelectorToken =\n\t\tstore.operation.open &&\n\t\tstore.operation.token.type === `writable_pure_selector`\n\t\t\t? store.operation.token\n\t\t\t: null\n\tconst currentSelectorTime =\n\t\tstore.operation.open &&\n\t\tstore.operation.token.type === `writable_pure_selector`\n\t\t\t? store.operation.timestamp\n\t\t\t: null\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 if (\n\t\t\t\tcurrentSelectorToken &&\n\t\t\t\tcurrentSelectorTime &&\n\t\t\t\tevent.type === `state_creation`\n\t\t\t) {\n\t\t\t\tbuildSelectorUpdate(\n\t\t\t\t\tstore,\n\t\t\t\t\ttl,\n\t\t\t\t\tevent.token,\n\t\t\t\t\tevent,\n\t\t\t\t\tcurrentSelectorToken,\n\t\t\t\t\tcurrentSelectorTime,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\taddToHistory(tl, 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\nfunction addToHistory(tl: Timeline<any>, event: TimelineEvent<any>): void {\n\tif (tl.at !== tl.history.length) {\n\t\ttl.history.splice(tl.at)\n\t}\n\ttl.history.push(event)\n\ttl.at = tl.history.length\n\ttl.subject.next(event)\n}\n","import type { TimelineEvent, TimelineToken } from \"atom.io\"\n\nimport {\n\tingestAtomUpdateEvent,\n\tingestCreationEvent,\n\tingestDisposalEvent,\n\tingestSelectorUpdateEvent,\n\tingestTransactionOutcomeEvent,\n} from \"../events\"\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\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\tlet nextIndex = timelineData.at\n\tlet events: TimelineEvent<any>[]\n\tswitch (action) {\n\t\tcase `undo`:\n\t\t\t--nextIndex\n\t\t\twhile (\n\t\t\t\tnextIndex !== 0 &&\n\t\t\t\ttimelineData.history[nextIndex].checkpoint !== true\n\t\t\t) {\n\t\t\t\t--nextIndex\n\t\t\t}\n\t\t\tevents = timelineData.history.slice(nextIndex, timelineData.at).reverse()\n\n\t\t\tbreak\n\t\tcase `redo`:\n\t\t\t++nextIndex\n\t\t\tevents = timelineData.history.slice(timelineData.at, nextIndex)\n\t}\n\ttimelineData.at = nextIndex\n\n\tconst applying = action === `redo` ? `newValue` : `oldValue`\n\n\tfor (const event of events) {\n\t\tswitch (event.type) {\n\t\t\tcase `atom_update`: {\n\t\t\t\tingestAtomUpdateEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `selector_update`: {\n\t\t\t\tingestSelectorUpdateEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `transaction_outcome`: {\n\t\t\t\tingestTransactionOutcomeEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `state_creation`: {\n\t\t\t\tingestCreationEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `state_disposal`: {\n\t\t\t\tingestDisposalEvent(store, event, applying)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\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,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;;;;;ACKtC,SAAgB,OACf,OACgC;AAChC,QAAO,MAAM,UAAU,KACtB,SAAQ,MAAM;AAEf,QAAO;;AAGR,SAAgB,OACf,OAC0C;AAC1C,QAAO,MAAM,WAAW,KACvB,SAAQ,MAAM;AAEf,QAAO;;;;;ACnBR,MAAM,oBACL;AAED,SAAgB,KAAK,OAA6B;CACjD,MAAM,cAAc,OAAO,UAAU,SAAS,KAAK,MAAM;AACzD,QAAO,kBAAkB,KAAK,YAAY;;;;;ACL3C,SAAgB,OACf,oBACA,eACI;AACJ,KAAI,KAAK,mBAAmB,CAC3B,QAAO,mBAAmB,cAAc;AAEzC,QAAO;;;;;;;;;;;;;;ACAR,IAAa,SAAb,cAA+B,QAAW;CACzC,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,OAAO;CAEd,AAAO,YACN,UAGC;EACD,IAAIA;EACJ,IAAIC;AACJ,SAAO,SAAS,WAAW;AAC1B,kBAAe;AACf,iBAAc;IACb;AACF,OAAK,UAAU;AACf,OAAK,SAAS;AACd,OAAK,IAAI,oBAAoB,UAAU,WAAW,IAAI,QAAQ,SAAS,CAAC;;CAGzE,AAAQ,KAAK,SAAqB,OAAU;AAC3C,MAAI,YAAY,KAAK,MAAM;AAC1B,QAAK,QAAQ,MAAM;AACnB,QAAK,OAAO;;;CAGd,AAAQ,KAAK,SAAqB,QAAa;AAC9C,MAAI,YAAY,KAAK,MAAM;AAC1B,QAAK,OAAO,OAAO;AACnB,QAAK,OAAO;;;CAId,AAAO,IAAI,OAA6B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