atom.io 0.40.7 → 0.40.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/data/index.js +1 -2
  2. package/dist/data/index.js.map +1 -1
  3. package/dist/employ-socket-D6wgByWh.js.map +1 -1
  4. package/dist/eslint-plugin/index.js.map +1 -1
  5. package/dist/{has-role-hv4-hJMw.js → has-role-CMlaUlaf.js} +30 -46
  6. package/dist/has-role-CMlaUlaf.js.map +1 -0
  7. package/dist/internal/index.d.ts.map +1 -1
  8. package/dist/internal/index.js +103 -174
  9. package/dist/internal/index.js.map +1 -1
  10. package/dist/introspection/index.d.ts.map +1 -1
  11. package/dist/introspection/index.js +13 -32
  12. package/dist/introspection/index.js.map +1 -1
  13. package/dist/is-fn-DY1wZ-md.js.map +1 -1
  14. package/dist/json/index.d.ts.map +1 -1
  15. package/dist/json/index.js.map +1 -1
  16. package/dist/main/index.d.ts.map +1 -1
  17. package/dist/main/index.js +1 -2
  18. package/dist/main/index.js.map +1 -1
  19. package/dist/mutex-store-CSvxY9i3.js.map +1 -1
  20. package/dist/react/index.d.ts.map +1 -1
  21. package/dist/react/index.js.map +1 -1
  22. package/dist/react-devtools/index.d.ts.map +1 -1
  23. package/dist/react-devtools/index.js +2 -4
  24. package/dist/react-devtools/index.js.map +1 -1
  25. package/dist/realtime/index.d.ts.map +1 -1
  26. package/dist/realtime/index.js +2 -3
  27. package/dist/realtime/index.js.map +1 -1
  28. package/dist/realtime-client/index.d.ts +1 -4
  29. package/dist/realtime-client/index.d.ts.map +1 -1
  30. package/dist/realtime-client/index.js +5 -20
  31. package/dist/realtime-client/index.js.map +1 -1
  32. package/dist/realtime-react/index.d.ts +2 -5
  33. package/dist/realtime-react/index.d.ts.map +1 -1
  34. package/dist/realtime-react/index.js +4 -15
  35. package/dist/realtime-react/index.js.map +1 -1
  36. package/dist/realtime-server/index.d.ts +36 -44
  37. package/dist/realtime-server/index.d.ts.map +1 -1
  38. package/dist/realtime-server/index.js +125 -171
  39. package/dist/realtime-server/index.js.map +1 -1
  40. package/dist/realtime-testing/index.d.ts +4 -2
  41. package/dist/realtime-testing/index.d.ts.map +1 -1
  42. package/dist/realtime-testing/index.js +13 -7
  43. package/dist/realtime-testing/index.js.map +1 -1
  44. package/dist/{shared-room-store-COGGKqes.js → shared-room-store-BfW3nWif.js} +2 -3
  45. package/dist/{shared-room-store-COGGKqes.js.map → shared-room-store-BfW3nWif.js.map} +1 -1
  46. package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -1
  47. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  48. package/dist/transceivers/set-rtx/index.js +4 -8
  49. package/dist/transceivers/set-rtx/index.js.map +1 -1
  50. package/dist/web/index.js.map +1 -1
  51. package/package.json +11 -11
  52. package/src/internal/mutable/tracker.ts +66 -51
  53. package/src/internal/subscribe/subscribe-to-state.ts +9 -0
  54. package/src/realtime-client/index.ts +0 -1
  55. package/src/realtime-react/index.ts +0 -1
  56. package/src/realtime-server/continuity/continuity-store.ts +1 -26
  57. package/src/realtime-server/continuity/provide-continuity.ts +50 -0
  58. package/src/realtime-server/continuity/{subscribe-to-continuity-actions.ts → provide-outcomes.ts} +14 -12
  59. package/src/realtime-server/continuity/{subscribe-to-continuity-perpectives.ts → provide-perspectives.ts} +10 -8
  60. package/src/realtime-server/continuity/{prepare-to-send-initial-payload.ts → provide-startup-payloads.ts} +6 -4
  61. package/src/realtime-server/continuity/receive-action-requests.ts +68 -0
  62. package/src/realtime-server/continuity/{prepare-to-track-client-acknowledgement.ts → track-acknowledgements.ts} +15 -8
  63. package/src/realtime-server/index.ts +1 -2
  64. package/src/realtime-server/ipc-sockets/custom-socket.ts +3 -3
  65. package/src/realtime-server/ipc-sockets/parent-socket.ts +19 -13
  66. package/src/realtime-server/server-config.ts +0 -1
  67. package/src/realtime-testing/setup-realtime-test.tsx +20 -14
  68. package/dist/has-role-hv4-hJMw.js.map +0 -1
  69. package/src/realtime-client/server-action.ts +0 -23
  70. package/src/realtime-react/use-server-action.ts +0 -19
  71. package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +0 -59
  72. package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +0 -145
  73. package/src/realtime-server/realtime-action-receiver.ts +0 -40
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["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","target","IMPLICIT: { readonly STORE: RootStore }","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>","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>","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>","token: WritablePureSelectorToken<AsJSON<T>>","updateToken: RegularAtomToken<SignalFrom<T>>","atomFamily","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>","token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>","relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>","tl: Timeline<ManagedAtom>","atomToken: AtomToken<any, any, any>","familyToken: AtomFamilyToken<any, any, any>","token: TimelineToken<ManagedAtom>","atomUpdate: AtomUpdateEvent<any> & TimelineEvent<any>","currentTxToken: TransactionToken<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/store/circular-buffer.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/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/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/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/subscribe-to-transaction.ts","../../src/internal/subscribe/subscribe-in-store.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/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","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","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 { 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 {\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 { 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 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\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 { 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 {\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,SAAS,SAAS,IAAI,MAAM;;;;;ACDpC,IAAa,iBAAb,MAAa,eAAkB;CAC9B,AAAU;CACV,AAAU,SAAS;CAGnB,AAAO,YAAY,eAA6B;EAC/C,IAAIA;AACJ,MAAI,OAAO,kBAAkB,SAC5B,UAAS;MAET,UAAS,cAAc;AAExB,OAAK,UAAU,MAAM,KAAK,EAAE;;CAG7B,IAAW,SAAuC;AACjD,SAAO,KAAK;;CAGb,IAAW,QAAgB;AAC1B,SAAO,KAAK;;CAGb,AAAO,IAAI,MAAe;AACzB,OAAK,QAAQ,KAAK,UAAU;AAC5B,OAA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WAAW,WAAW,SAAS,aAAa;AAElD,MAAK,MAAM,SAAS,OACnB,SAAQ,MAAM,MAAd;EACC,KAAK;AACJ,yBAAsB,OAAO,OAAO;AACpC;EAED,KAAK;AACJ,6BAA0B,OAAO,OAAO;AACxC;EAED,KAAK;AACJ,iCAA8B,OAAO,OAAO;AAC5C;EAED,KAAK;AACJ,uBAAoB,OAAO,OAAO;AAClC;EAED,KAAK;AACJ,uBAAoB,OAAO,OAAO;AAClC;;AAKH,cAAa,QAAQ,KAAK;AAC1B,cAAa,gBAAgB;AAC7B,OAAM,OAAO,KACZ,MACA,YACA,MAAM,KACN,IAAI,MAAM,IAAI,cAAc,aAAa,GAAG,KAAK,aAAa,QAAQ"}
1
+ {"version":3,"file":"index.js","names":["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 }","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>","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>","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>>","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>","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/store/circular-buffer.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/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/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/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/subscribe-to-transaction.ts","../../src/internal/subscribe/subscribe-in-store.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/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","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","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 { 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 {\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 { 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 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\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 { 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 {\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;;;;;ACDtC,IAAa,iBAAb,MAAa,eAAkB;CAC9B,AAAU;CACV,AAAU,SAAS;CAGnB,AAAO,YAAY,eAA6B;EAC/C,IAAIA;AACJ,MAAI,OAAO,kBAAkB,SAC5B,UAAS;MAET,UAAS,cAAc;AAExB,OAAK,UAAU,MAAM,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