atom.io 0.16.0 โ†’ 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mutable/create-mutable-atom.ts","../src/lineage.ts","../src/store/deposit.ts","../src/store/store.ts","../../../rel8/junction/src/junction.ts","../src/subject.ts","../src/store/withdraw.ts","../src/store/withdraw-new-family-member.ts","../src/future.ts","../src/set-state/copy-mutable-if-needed.ts","../src/set-state/copy-mutable-in-transaction.ts","../src/caching.ts","../src/read-or-compute-value.ts","../src/selector/register-selector.ts","../src/set-state/become.ts","../src/operation.ts","../src/set-state/emit-update.ts","../src/set-state/evict-downstream.ts","../src/set-state/stow-update.ts","../src/set-state/set-atom.ts","../src/set-state/set-atom-or-selector.ts","../src/keys.ts","../src/selector/get-selector-dependency-keys.ts","../src/selector/trace-selector-atoms.ts","../src/selector/update-selector-atoms.ts","../src/selector/create-readonly-selector.ts","../src/selector/create-writable-selector.ts","../src/selector/create-standalone-selector.ts","../src/selector/delete-selector.ts","../src/subscribe/recall-state.ts","../src/subscribe/subscribe-to-root-atoms.ts","../src/subscribe/subscribe-to-state.ts","../src/subscribe/subscribe-to-timeline.ts","../src/subscribe/subscribe-to-transaction.ts","../src/mutable/tracker.ts","../src/mutable/create-mutable-atom-family.ts","../src/mutable/tracker-family.ts","../src/families/create-regular-atom-family.ts","../src/families/create-atom-family.ts","../src/families/create-readonly-selector-family.ts","../src/families/create-writable-selector-family.ts","../src/families/create-selector-family.ts","../src/mutable/get-json-family.ts","../src/mutable/get-json-token.ts","../src/mutable/get-update-token.ts","../src/mutable/is-mutable.ts","../src/mutable/transceiver.ts","../src/atom/create-regular-atom.ts","../src/atom/is-default.ts","../src/atom/create-standalone-atom.ts","../src/atom/delete-atom.ts","../src/get-environment-data.ts","../src/ingest-updates/ingest-atom-update.ts","../src/ingest-updates/ingest-selector-update.ts","../src/ingest-updates/ingest-transaction-update.ts","../src/lazy-map.ts","../src/not-found-error.ts","../src/timeline/add-atom-to-timeline.ts","../src/timeline/create-timeline.ts","../src/timeline/time-travel.ts","../src/transaction/abort-transaction.ts","../src/transaction/apply-transaction.ts","../src/transaction/build-transaction.ts","../src/transaction/create-transaction.ts","../src/transaction/index.ts"],"names":["setState","a","b","withdraw","target","update","unsubscribe","store","stringifyJson","isMutable","_a","_b","updates","token","findInStore","getState","key"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAMA,SAAS,YAAAA,iBAAgB;AAEzB,SAAS,kBAAkB;;;ACHpB,SAAS,OAA0B,OAAa;AACtD,SAAO,MAAM,UAAU,MAAM;AAC5B,YAAQ,MAAM;AAAA,EACf;AACA,SAAO;AACR;;;ACwBO,SAAS,QACf,OAUsB;AACtB,QAAM,QAAQ;AAAA,IACb,KAAK,MAAM;AAAA,IACX,MAAM,MAAM;AAAA,EACb;AACA,MAAI,YAAY,OAAO;AACtB,UAAM,SAAS,MAAM;AAAA,EACtB;AACA,SAAO;AACR;;;ACtDA,SAAS,oBAAoB;;;ACoDtB,IAAM,WAAN,MAIL;AAAA,EA0FM,YACN,MACA,QACC;AAzFF,SAAgB,YAAY,oBAAI,IAAyB;AACzD,SAAgB,WAAW,oBAAI,IAAqB;AAGpD,SAAO,iBAAiB,CAAC,GAAW,MAAsB,GAAG,CAAC,IAAI,CAAC;AAhEpE;AAsJE,SAAK,IAAI,KAAK,QAAQ,CAAC;AACvB,SAAK,IAAI,KAAK,QAAQ,CAAC;AAEvB,SAAK,cAAc,KAAK;AACxB,QAAI,EAAC,iCAAQ,gBAAe;AAC3B,WAAK,YAAY,IAAI,KAAI,UAAK,cAAL,mBAAgB,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,EAAE;AACzE,WAAK,WAAW,IAAI,IAAI,KAAK,QAAQ;AAAA,IACtC;AACA,SAAK,aAAY,sCAAQ,cAAR,YAAqB;AACtC,QAAI,iCAAQ,gBAAgB;A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BAAiC;AAAA,IACtC,KAAK,QAAQ;AAAA,IACb,MAAM;AAAA,IACN,KAAK,CAAC,QAAuB,OAAgB;AAC5C,uBAAiB,QAAQ,KAAK,QAAQ,OAAO,EAAE;AAC/C,UAAI;AACH,cAAMZ,UAAS,OAAO,KAAK;AAE3B,cAAM,EAAE,YAAY,IAAIA,QAAO;AAC/B,cAAM,SAAS,QAAQ,GAAG,aAAa,GAAG,MAAM;AAChD,yBAAiB,QAAQA,OAAM;AAC/B,eAAO;AAAA,MACR,SAAS,QAAQ;AAChB,yBAAiB,MAAM;AACvB,cAAM,OAAO,KAAK,aAAM,eAAe,QAAQ,KAAK,WAAW,MAAM;AACrE,cAAM;AAAA,MACP;AAAA,IACD;AAAA,IACA,SAAS,CAACG,WAAU,kBAAkB,SAASA,MAAK;AAAA,IACpD,SAAS,IAAI,QAAQ;AAAA,EACtB;AACA,QAAM,SAAS,OAAO,KAAK;AAC3B,SAAO,aAAa,IAAI,eAAe,KAAK,cAAc;AAC1D,QAAM,QAAQ,QAAQ,cAAc;AACpC,QAAM,GAAG,oBAAoB,KAAK,KAAK;AACvC,SAAO;AACR;;;AC9CO,IAAM,qBAAqB,CAAC,QAAQ,YAAY,UAAU","sourcesContent":["import type { UpdateHandler } from \"atom.io\"\nimport type {\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n} from \"atom.io\"\nimport { setState } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJson } from \"atom.io/json\"\n\nimport { type MutableAtom, cacheValue } from \"..\"\nimport { createRegularAtom, markAtomAsDefault } from \"../atom\"\nimport { newest } from \"../lineage\"\nimport { type Store, deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtom<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(\n\toptions: MutableAtomOptions<T, J>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): MutableAtomToken<T, J> {\n\tstore.logger.info(\n\t\t`๐Ÿ”จ`,\n\t\t`atom`,\n\t\toptions.key,\n\t\t`creating in store \"${store.config.name}\"`,\n\t)\n\tconst target = newest(store)\n\tconst existing = target.atoms.get(options.key)\n\tif (existing && existing.type === `mutable_atom`) {\n\t\tstore.logger.error(\n\t\t\t`โŒ`,\n\t\t\t`atom`,\n\t\t\toptions.key,\n\t\t\t`Tried to create atom, but it already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: MutableAtom<T, J> = {\n\t\t...options,\n\t\ttype: `mutable_atom`,\n\t\tinstall: (store: Store) => {\n\t\t\tstore.logger.info(\n\t\t\t\t`๐Ÿ› ๏ธ`,\n\t\t\t\t`atom`,\n\t\t\t\toptions.key,\n\t\t\t\t`installing in store \"${store.config.name}\"`,\n\t\t\t)\n\t\t\treturn createMutableAtom(options, family, store)\n\t\t},\n\t\tsubject,\n\t} as const\n\tif (family) {\n\t\tnewAtom.family = family\n\t}\n\tconst initialValue = options.default()\n\ttarget.atoms.set(newAtom.key, newAtom)\n\tmarkAtomAsDefault(options.key, store)\n\tcacheValue(options.key, initialValue, subject, target)\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\tsetSelf: (next) => setState(token, next, store),\n\t\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\t\tsubscribeToState(token, handle, `effect[${effectIndex}]`, store),\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\tselectJson(token, options, store)\n\n\tstore.on.atomCreation.next(token)\n\n\treturn token\n}\n","export interface Lineage {\n\tparent: typeof this | null\n\tchild: typeof this | null\n}\n\nexport function newest<T extends Lineage>(scion: T): T {\n\twhile (scion.child !== null) {\n\t\tscion = scion.child\n\t}\n\treturn scion\n}\n","import type {\n\tMutableAtomToken,\n\tReadableToken,\n\tReadonlySelectorToken,\n\tRegularAtomToken,\n\tSelectorToken,\n\tTransactionToken,\n\tWritableSelectorToken,\n\tWritableToken,\n\tฦ’n,\n} from \"atom.io\"\n\nimport type {\n\tMutableAtom,\n\tReadableState,\n\tReadonlySelector,\n\tRegularAtom,\n\tTransceiver,\n\tWritableSelector,\n\tWritableState,\n} from \"..\"\nimport type { Transaction } from \"../transaction\"\n\nexport function deposit<T>(state: RegularAtom<T>): RegularAtomToken<T>\nexport function deposit<T extends Transceiver<any>>(\n\tstate: MutableAtom<T, any>,\n): MutableAtomToken<T, any>\nexport function deposit<T>(state: WritableSelector<T>): WritableSelectorToken<T>\nexport function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>\nexport function deposit<T>(state: WritableState<T>): WritableToken<T>\nexport function deposit<T>(\n\tstate: Transaction<T extends ฦ’n ? T : never>,\n): TransactionToken<T>\nexport function deposit<T>(state: ReadableState<T>): ReadableToken<T>\nexport function deposit<T>(\n\tstate:\n\t\t| ReadonlySelector<T>\n\t\t| RegularAtom<T>\n\t\t| Transaction<T extends ฦ’n ? T : never>\n\t\t| WritableSelector<T>\n\t\t| (T extends Transceiver<any> ? MutableAtom<T, any> : never),\n):\n\t| MutableAtomToken<T extends Transceiver<any> ? T : never, any>\n\t| RegularAtomToken<T>\n\t| SelectorToken<T>\n\t| TransactionToken<T> {\n\tconst token = {\n\t\tkey: state.key,\n\t\ttype: state.type,\n\t} as any\n\tif (`family` in state) {\n\t\ttoken.family = state.family\n\t}\n\treturn token\n}\n","import { AtomIOLogger } from \"atom.io\"\nimport type {\n\tAtomToken,\n\tLogger,\n\tMutableAtomFamily,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tRegularAtomFamily,\n\tRegularAtomToken,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableSelectorFamily,\n\tWritableSelectorToken,\n\tฦ’n,\n} from \"atom.io\"\n\nimport { Junction } from \"~/packages/rel8/junction/src\"\n\nimport type {\n\tAtom,\n\tReadonlySelector,\n\tTracker,\n\tTransceiver,\n\tWritableSelector,\n} from \"..\"\nimport type { Lineage } from \"../lineage\"\nimport { getJsonToken, getUpdateToken } from \"../mutable\"\nimport type { OperationProgress } from \"../operation\"\nimport { StatefulSubject, Subject } from \"../subject\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction, TransactionMeta } from \"../transaction\"\n\nexport class Store implements Lineage {\n\tpublic parent: Store | null = null\n\tpublic child: Store | null = null\n\n\tpublic valueMap = new Map<string, any>()\n\n\tpublic atoms = new Map<string, Atom<any>>()\n\tpublic selectors = new Map<string, WritableSelector<any>>()\n\tpublic readonlySelectors = new Map<string, ReadonlySelector<any>>()\n\n\tpublic trackers = new Map<string, Tracker<Transceiver<any>>>()\n\tpublic families = new Map<\n\t\tstring,\n\t\t| MutableAtomFamily<any, any, any>\n\t\t| ReadonlySelectorFamily<any, any>\n\t\t| RegularAtomFamily<any, any>\n\t\t| WritableSelectorFamily<any, any>\n\t>()\n\n\tpublic timelines = new Map<string, Timeline<any>>()\n\tpublic transactions = new Map<string, Transaction<ฦ’n>>()\n\n\tpublic atomsThatAreDefault = new Set<string>()\n\n\tpublic timelineAtoms = new Junction({\n\t\tbetween: [`timelineKey`, `atomKey`],\n\t\tcardinality: `1:n`,\n\t})\n\tpublic selectorAtoms = new Junction({\n\t\tbetween: [`selectorKey`, `atomKey`],\n\t\tcardinality: `n:n`,\n\t})\n\tpublic selectorGraph = new Junction<\n\t\t`upstreamSelectorKey`,\n\t\t`downstreamSelectorKey`,\n\t\t{ source: string }\n\t>(\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\n\tpublic on = {\n\t\tatomCreation: new Subject<AtomToken<unknown>>(),\n\t\tselectorCreation: new Subject<\n\t\t\tReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>\n\t\t>(),\n\t\ttransactionCreation: new Subject<TransactionToken<ฦ’n>>(),\n\t\ttimelineCreation: new Subject<TimelineToken<unknown>>(),\n\t\ttransactionApplying: new StatefulSubject<TransactionMeta<ฦ’n> | null>(null),\n\t\toperationClose: new Subject<OperationProgress>(),\n\t}\n\tpublic operation: OperationProgress = { open: false }\n\tpublic transactionMeta: TransactionMeta<ฦ’n> | null = null\n\n\tpublic config: {\n\t\tname: string\n\t} = {\n\t\tname: `IMPLICIT_STORE`,\n\t}\n\n\tpublic loggers: AtomIOLogger[] = [\n\t\tnew AtomIOLogger(`warn`, (_, __, key) => !key.includes(`๐Ÿ‘โ€๐Ÿ—จ`)),\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(name: string, store: Store | null = null) {\n\t\tif (store !== null) {\n\t\t\tthis.valueMap = new Map(store?.valueMap)\n\t\t\tthis.operation = { ...store?.operation }\n\t\t\tthis.transactionMeta = null\n\t\t\tthis.config = {\n\t\t\t\t...store?.config,\n\t\t\t\tname,\n\t\t\t}\n\t\t\tfor (const [, family] of store.families) {\n\t\t\t\tfamily.install(this)\n\t\t\t}\n\t\t\tconst mutableHelpers = new Set<string>()\n\t\t\tfor (const [, atom] of store.atoms) {\n\t\t\t\tif (mutableHelpers.has(atom.key)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tatom.install(this)\n\t\t\t\tif (atom.type === `mutable_atom`) {\n\t\t\t\t\tconst originalJsonToken = getJsonToken(atom)\n\t\t\t\t\tconst originalUpdateToken = getUpdateToken(atom)\n\t\t\t\t\tmutableHelpers.add(originalJsonToken.key)\n\t\t\t\t\tmutableHelpers.add(originalUpdateToken.key)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [, selector] of store.readonlySelectors) {\n\t\t\t\tselector.install(this)\n\t\t\t}\n\t\t\tfor (const [, selector] of store.selectors) {\n\t\t\t\tif (mutableHelpers.has(selector.key)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tselector.install(this)\n\t\t\t}\n\t\t\tfor (const [, tx] of store.transactions) {\n\t\t\t\ttx.install(this)\n\t\t\t}\n\t\t\tfor (const [, timeline] of store.timelines) {\n\t\t\t\ttimeline.install(this)\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const IMPLICIT = {\n\tSTORE_INTERNAL: undefined as Store | undefined,\n\tget STORE(): Store {\n\t\treturn (\n\t\t\tthis.STORE_INTERNAL ?? (this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`))\n\t\t)\n\t},\n}\n\nexport const clearStore = (store: Store): void => {\n\tconst { config } = store\n\tObject.assign(store, new Store(config.name))\n\tstore.config = config\n}\n","import type { Cardinality, Json, Refinement } from \"rel8\"\n\nexport interface JunctionEntries<Content extends Json.Object | null>\n\textends Json.Object {\n\treadonly relations: [string, string[]][]\n\treadonly contents: [string, Content][]\n}\nexport interface JunctionSchema<ASide extends string, BSide extends string>\n\textends Json.Object {\n\treadonly between: [a: ASide, b: BSide]\n\treadonly cardinality: Cardinality\n}\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<Content extends Json.Object | null> = {\n\texternalStore?: ExternalStoreConfiguration<Content>\n\tisContent?: Refinement<unknown, Content>\n\tmakeContentKey?: (a: string, b: string) => string\n}\n\nexport type JunctionJSON<\n\tASide extends string,\n\tBSide extends string,\n\tContent extends Json.Object | null,\n> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>\n\nexport class Junction<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Content extends Json.Object | null = null,\n> {\n\tpublic readonly a: ASide\n\tpublic readonly b: BSide\n\tpublic readonly cardinality: Cardinality\n\tpublic readonly relations = new Map<string, Set<string>>()\n\tpublic readonly contents = new Map<string, Content>()\n\n\tpublic isContent: Refinement<unknown, Content> | null\n\tpublic makeContentKey = (a: string, b: string): string => `${a}:${b}`\n\n\tpublic getRelatedKeys(key: string): Set<string> | undefined {\n\t\treturn this.relations.get(key)\n\t}\n\tprotected addRelation(a: string, b: string): void {\n\t\tlet aRelations = this.relations.get(a)\n\t\tlet bRelations = this.relations.get(b)\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: string, b: string): void {\n\t\tconst aRelations = this.relations.get(a)\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)\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: string, bs: string[]): void {\n\t\tthis.relations.set(a, new Set(bs))\n\t\tfor (const b of bs) {\n\t\t\tconst bRelations = new Set([a])\n\t\t\tthis.relations.set(b, bRelations)\n\t\t}\n\t}\n\tprotected replaceRelationsSafely(a: string, bs: string[]): void {\n\t\tconst aRelationsPrev = this.relations.get(a)\n\t\tif (aRelationsPrev) {\n\t\t\tfor (const b of aRelationsPrev) {\n\t\t\t\tconst bRelations = this.relations.get(b)\n\t\t\t\tif (bRelations) {\n\t\t\t\t\tif (bRelations.size === 1) {\n\t\t\t\t\t\tthis.relations.delete(b)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbRelations.delete(a)\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(a, new Set(bs))\n\t\tfor (const b of bs) {\n\t\t\tlet bRelations = this.relations.get(b)\n\t\t\tif (bRelations) {\n\t\t\t\tbRelations.add(a)\n\t\t\t} else {\n\t\t\t\tbRelations = new Set([a])\n\t\t\t\tthis.relations.set(b, bRelations)\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected getContentInternal(contentKey: string): Content | undefined {\n\t\treturn this.contents.get(contentKey)\n\t}\n\tprotected setContent(contentKey: string, content: Content): void {\n\t\tthis.contents.set(contentKey, content)\n\t}\n\tprotected deleteContent(contentKey: string): void {\n\t\tthis.contents.delete(contentKey)\n\t}\n\n\tpublic constructor(\n\t\tdata: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>,\n\t\tconfig?: JunctionAdvancedConfiguration<Content>,\n\t) {\n\t\tthis.a = data.between[0]\n\t\tthis.b = data.between[1]\n\n\t\tthis.cardinality = data.cardinality\n\t\tif (!config?.externalStore) {\n\t\t\tthis.relations = new Map(data.relations?.map(([a, b]) => [a, new Set(b)]))\n\t\t\tthis.contents = new Map(data.contents)\n\t\t}\n\t\tthis.isContent = config?.isContent ?? null\n\t\tif (config?.makeContentKey) {\n\t\t\tthis.makeContentKey = config.makeContentKey\n\t\t}\n\t\tif (config?.externalStore) {\n\t\t\tconst externalStore = config.externalStore\n\t\t\tthis.has = (a, b) => externalStore.has(a, b)\n\t\t\tthis.addRelation = (a, b) => {\n\t\t\t\texternalStore.addRelation(a, b)\n\t\t\t}\n\t\t\tthis.deleteRelation = (a, b) => {\n\t\t\t\texternalStore.deleteRelation(a, b)\n\t\t\t}\n\t\t\tthis.replaceRelationsSafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsSafely(a, bs)\n\t\t\t}\n\t\t\tthis.replaceRelationsUnsafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsUnsafely(a, bs)\n\t\t\t}\n\t\t\tthis.getRelatedKeys = (key) => externalStore.getRelatedKeys(key)\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\tfor (const y of ys) this.addRelation(x, y)\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}\n\tpublic toJSON(): JunctionJSON<ASide, BSide, 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(([a, b]) => [a, [...b]]),\n\t\t\tcontents: [...this.contents.entries()],\n\t\t}\n\t}\n\n\tpublic set(\n\t\ta: string,\n\t\t...rest: Content extends null ? [b: string] : [b: string, content: Content]\n\t): this\n\tpublic set(\n\t\trelation: { [Key in ASide | BSide]: string },\n\t\t...rest: Content extends null ? [] | [b?: undefined] : [content: Content]\n\t): this\n\tpublic set(\n\t\ta: string | { [Key in ASide | BSide]: string },\n\t\t...rest: Content extends null\n\t\t\t? [] | [b?: string | undefined]\n\t\t\t: [b: string, content: Content] | [content: Content]\n\t): this {\n\t\tconst b: string =\n\t\t\ttypeof rest[0] === `string`\n\t\t\t\t? rest[0]\n\t\t\t\t: (a[this.b as keyof typeof a] as string)\n\t\tconst content: Content | undefined =\n\t\t\trest[1] ?? typeof rest[0] === `string` ? undefined : (rest[0] as Content)\n\t\ta = typeof a === `string` ? a : a[this.a]\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(bPrev, a)\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst aPrev = this.getRelatedKey(b)\n\t\t\t\tif (aPrev && aPrev !== a) this.delete(aPrev, b)\n\t\t\t}\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: string, b?: string): this\n\tpublic delete(\n\t\trelation:\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>,\n\t\tb?: undefined,\n\t): this\n\tpublic delete(\n\t\tx:\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>\n\t\t\t| string,\n\t\tb?: string | undefined,\n\t): this {\n\t\t// @ts-expect-error we deduce that this.b may index x\n\t\tb = typeof b === `string` ? b : (x[this.b] as string | undefined)\n\t\t// @ts-expect-error we deduce that this.a may index x\n\t\tconst a = typeof x === `string` ? x : (x[this.a] as string | undefined)\n\n\t\tif (a === undefined && typeof b === `string`) {\n\t\t\tconst bRelations = this.getRelatedKeys(b)\n\t\t\tif (bRelations) {\n\t\t\t\tfor (const a of bRelations) {\n\t\t\t\t\tthis.delete(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && b === undefined) {\n\t\t\tconst aRelations = this.getRelatedKeys(a)\n\t\t\tif (aRelations) {\n\t\t\t\tfor (const b of aRelations) {\n\t\t\t\t\tthis.delete(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && typeof b === `string`) {\n\t\t\tthis.deleteRelation(a, b)\n\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\tthis.deleteContent(contentKey)\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic getRelatedKey(key: string): string | undefined {\n\t\tconst relations = this.getRelatedKeys(key)\n\t\tif (relations) {\n\t\t\tif (relations.size > 1) {\n\t\t\t\tconsole.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\tfor (const relation of relations) {\n\t\t\t\treturn relation\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic replaceRelations(\n\t\ta: string,\n\t\trelations: Content extends null ? string[] : Record<string, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this {\n\t\tconst hasContent = !Array.isArray(relations)\n\t\tconst bs = hasContent ? Object.keys(relations) : relations\n\t\tif (config?.reckless) {\n\t\t\tthis.replaceRelationsUnsafely(a, bs)\n\t\t} else {\n\t\t\tthis.replaceRelationsSafely(a, bs)\n\t\t}\n\t\tif (hasContent) {\n\t\t\tfor (const b of bs) {\n\t\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\t\tconst content = relations[b] as Content\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: string, b: string): Content | undefined {\n\t\tconst contentKey = this.makeContentKey(a, b)\n\t\treturn this.getContentInternal(contentKey)\n\t}\n\n\tpublic getRelationEntries(\n\t\tinput: Record<ASide, string> | Record<BSide, string>,\n\t): [string, Content][] {\n\t\tconst a: string | undefined = (input as any)[this.a]\n\t\tconst b: string | 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((b) => {\n\t\t\t\t\treturn [b, this.getContent(a, b) ?? (null 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((a) => {\n\t\t\t\t\treturn [a, this.getContent(a, b) ?? (null as Content)]\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn []\n\t}\n\n\tpublic has(a: string, b?: string): boolean {\n\t\tif (b) {\n\t\t\tconst setA = this.getRelatedKeys(a)\n\t\t\treturn setA?.has(b) ?? false\n\t\t}\n\t\treturn this.relations.has(a)\n\t}\n}\n","export class Subject<T> {\n\tpublic Subscriber: (value: T) => void\n\n\tpublic subscribers: Map<string, this[`Subscriber`]> = new Map()\n\n\tpublic subscribe(key: string, subscriber: this[`Subscriber`]): () => void {\n\t\tthis.subscribers.set(key, subscriber)\n\t\tconst unsubscribe = () => this.unsubscribe(key)\n\t\treturn unsubscribe\n\t}\n\n\tprivate unsubscribe(key: string) {\n\t\tthis.subscribers.delete(key)\n\t}\n\n\tpublic next(value: T): void {\n\t\tconst subscribers = this.subscribers.values()\n\t\tfor (const subscriber of subscribers) {\n\t\t\tsubscriber(value)\n\t\t}\n\t}\n}\n\nexport class StatefulSubject<T> extends Subject<T> {\n\tpublic state: T\n\n\tpublic constructor(initialState: T) {\n\t\tsuper()\n\t\tthis.state = initialState\n\t}\n\n\tpublic next(value: T): void {\n\t\tthis.state = value\n\t\tsuper.next(value)\n\t}\n}\n","import type {\n\tAtomToken,\n\tMutableAtomToken,\n\tReadableToken,\n\tReadonlySelectorToken,\n\tRegularAtomToken,\n\tSelectorToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableSelectorToken,\n\tWritableToken,\n\tฦ’n,\n} from \"atom.io\"\n\nimport type {\n\tAtom,\n\tMutableAtom,\n\tReadableState,\n\tReadonlySelector,\n\tRegularAtom,\n\tSelector,\n\tTransceiver,\n\tWritableSelector,\n\tWritableState,\n} from \"..\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Store } from \"./store\"\n\nexport type Withdrawable = ReadableState<any> | Timeline<any> | Transaction<any>\n\nexport function withdraw<T>(\n\ttoken: RegularAtomToken<T>,\n\tstore: Store,\n): RegularAtom<T> | undefined\nexport function withdraw<T extends Transceiver<any>>(\n\ttoken: MutableAtomToken<T, any>,\n\tstore: Store,\n): MutableAtom<T, any> | undefined\nexport function withdraw<T>(\n\ttoken: AtomToken<T>,\n\tstore: Store,\n): Atom<T> | undefined\nexport function withdraw<T>(\n\ttoken: WritableSelectorToken<T>,\n\tstore: Store,\n): WritableSelector<T> | undefined\nexport function withdraw<T>(\n\ttoken: ReadonlySelectorToken<T>,\n\tstore: Store,\n): ReadonlySelector<T> | undefined\nexport function withdraw<T>(\n\ttoken: SelectorToken<T>,\n\tstore: Store,\n): Selector<T> | undefined\nexport function withdraw<T>(\n\ttoken: WritableToken<T>,\n\tstore: Store,\n): WritableState<T> | undefined\nexport function withdraw<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Store,\n): ReadableState<T> | undefined\nexport function withdraw<T>(\n\ttoken: TransactionToken<T>,\n\tstore: Store,\n): Transaction<T extends ฦ’n ? T : never> | undefined\nexport function withdraw<T>(\n\ttoken: TimelineToken<T>,\n\tstore: Store,\n): Timeline<T extends TimelineManageable ? T : never> | undefined\nexport function withdraw<T>(\n\ttoken:\n\t\t| RegularAtomToken<T>\n\t\t| SelectorToken<T>\n\t\t| TimelineToken<T>\n\t\t| TransactionToken<T>\n\t\t| (T extends Transceiver<any> ? MutableAtomToken<T, any> : never),\n\tstore: Store,\n): Withdrawable | undefined {\n\tlet withdrawn: Withdrawable | undefined\n\tlet target: Store | null = store\n\twhile (target !== null) {\n\t\tswitch (token.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\twithdrawn = target.atoms.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `selector`:\n\t\t\t\twithdrawn = target.selectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `readonly_selector`:\n\t\t\t\twithdrawn = target.readonlySelectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `timeline`:\n\t\t\t\twithdrawn = target.timelines.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `transaction`:\n\t\t\t\twithdrawn = target.transactions.get(token.key)\n\t\t\t\tbreak\n\t\t}\n\t\tif (withdrawn) {\n\t\t\treturn withdrawn\n\t\t}\n\t\ttarget = target.child\n\t}\n}\n","import type {\n\tReadableToken,\n\tReadonlySelectorToken,\n\tRegularAtomToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type {\n\tAtom,\n\tReadableState,\n\tReadonlySelector,\n\tStore,\n\tWritableSelector,\n\tWritableState,\n} from \"..\"\nimport { newest, withdraw } from \"..\"\n\nexport function withdrawNewFamilyMember<T>(\n\ttoken: RegularAtomToken<T>,\n\tstore: Store,\n): Atom<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: WritableSelectorToken<T>,\n\tstore: Store,\n): WritableSelector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadonlySelectorToken<T>,\n\tstore: Store,\n): ReadonlySelector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: WritableToken<T>,\n\tstore: Store,\n): WritableState<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Store,\n): ReadableState<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Store,\n): ReadableState<T> | undefined {\n\tif (token.family) {\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ‘ช`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`creating new family member in store \"${store.config.name}\"`,\n\t\t)\n\t\tconst target = newest(store)\n\t\tconst family = target.families.get(token.family.key)\n\t\tif (family) {\n\t\t\tconst jsonSubKey = JSON.parse(token.family.subKey)\n\t\t\tfamily(jsonSubKey)\n\t\t\tconst state = withdraw(token, store)\n\t\t\treturn state\n\t\t}\n\t}\n\treturn undefined\n}\n","/**\n * A Promise that can be canceled.\n * @internal\n * @private\n * @typeParam T The type of the value that the promise will resolve to.\n *\n * @remarks\n * Can be constructed like a Promise, or from an existing Promise.\n */\nexport class Future<T> extends Promise<T> {\n\tpublic isCanceled = false\n\n\tpublic constructor(\n\t\texecutor:\n\t\t\t| Promise<T>\n\t\t\t| ((resolve: (value: T) => void, reject: (reason?: any) => void) => void),\n\t) {\n\t\tsuper((resolve, reject) => {\n\t\t\tconst pass = (value: T) =>\n\t\t\t\tthis.isCanceled ? reject(`canceled`) : resolve(value)\n\t\t\tconst fail = (reason: any) =>\n\t\t\t\tthis.isCanceled ? reject(`canceled`) : reject(reason)\n\t\t\tif (typeof executor === `function`) {\n\t\t\t\texecutor(pass, fail)\n\t\t\t} else {\n\t\t\t\texecutor.then(pass, fail)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic cancel(): void {\n\t\tthis.isCanceled = true\n\t}\n}\n","import type { JsonInterface } from \"atom.io/json\"\n\nimport type { MutableAtom, Transceiver } from \"..\"\nimport { Tracker } from \"../mutable\"\nimport type { Store } from \"../store\"\n\nexport function copyMutableIfNeeded<T extends Transceiver<any>>(\n\tatom: MutableAtom<T, any>,\n\torigin: Store,\n\ttarget: Store,\n): T {\n\tconst originValue = origin.valueMap.get(atom.key)\n\tconst targetValue = target.valueMap.get(atom.key)\n\tif (originValue === targetValue) {\n\t\torigin.logger.info(`๐Ÿ“ƒ`, `atom`, `${atom.key}`, `copying`)\n\t\tconst jsonValue = atom.toJson(originValue)\n\t\tconst copiedValue = atom.fromJson(jsonValue)\n\t\ttarget.valueMap.set(atom.key, copiedValue)\n\t\tnew Tracker(atom, origin)\n\t\treturn copiedValue\n\t}\n\treturn targetValue\n}\n","import { newest } from \"..\"\nimport type { Atom, Store } from \"..\"\nimport { copyMutableIfNeeded } from \"./copy-mutable-if-needed\"\n\nexport function copyMutableIfWithinTransaction<T>(\n\toldValue: T,\n\tatom: Atom<T>,\n\tstore: Store,\n): T {\n\tconst target = newest(store)\n\tconst parent = target.parent\n\tif (parent !== null) {\n\t\tif (atom.type === `mutable_atom`) {\n\t\t\tconst copiedValue = copyMutableIfNeeded(atom, parent, target)\n\t\t\treturn copiedValue\n\t\t}\n\t}\n\treturn oldValue\n}\n","import type { StateUpdate } from \"atom.io\"\nimport type { ReadableState } from \".\"\nimport { Future } from \"./future\"\nimport { copyMutableIfWithinTransaction } from \"./set-state/copy-mutable-in-transaction\"\nimport type { Store } from \"./store\"\nimport type { Subject } from \"./subject\"\n\nexport function cacheValue<T>(\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n\tstore: Store,\n): T\nexport function cacheValue<T extends Promise<any>>(\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n\tstore: Store,\n): Future<T>\nexport function cacheValue<T>(\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n\ttarget: Store,\n): Future<T> | T {\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future) {\n\t\tcurrentValue.cancel()\n\t}\n\tif (value instanceof Promise) {\n\t\tconst future = new Future<T>(value)\n\t\ttarget.valueMap.set(key, future)\n\t\tfuture\n\t\t\t.then((resolved) => {\n\t\t\t\tif (future.isCanceled) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tcacheValue(key, resolved, subject, target)\n\t\t\t\tsubject.next({ newValue: resolved, oldValue: future })\n\t\t\t})\n\t\t\t.catch((thrown) => {\n\t\t\t\tif (thrown !== `canceled`) {\n\t\t\t\t\ttarget.logger.error(`๐Ÿ’ฅ`, `state`, key, `rejected:`, thrown)\n\t\t\t\t}\n\t\t\t})\n\t\treturn future\n\t}\n\ttarget.valueMap.set(key, value)\n\treturn value\n}\n\nexport const readCachedValue = <T>(\n\ttoken: ReadableState<any>,\n\ttarget: Store,\n): T => {\n\tlet value = target.valueMap.get(token.key) as T\n\tif (token.type === `atom`) {\n\t\tvalue = copyMutableIfWithinTransaction(value, token, target)\n\t}\n\treturn value\n}\n\nexport const evictCachedValue = (key: string, target: Store): void => {\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future) {\n\t\tcurrentValue.cancel()\n\t}\n\tif (target.operation.open) {\n\t\ttarget.operation.prev.set(key, currentValue)\n\t}\n\ttarget.valueMap.delete(key)\n\ttarget.logger.info(`๐Ÿ—‘`, `state`, key, `evicted`)\n}\n","import type { ReadableState } from \".\"\nimport { readCachedValue } from \"./caching\"\nimport type { Store } from \"./store\"\n\nexport const readOrComputeValue = <T>(\n\tstate: ReadableState<T>,\n\ttarget: Store,\n): T => {\n\tif (target.valueMap.has(state.key)) {\n\t\ttarget.logger.info(`๐Ÿ“–`, state.type, state.key, `reading cached value`)\n\t\treturn readCachedValue(state, target)\n\t}\n\tif (state.type !== `atom` && state.type !== `mutable_atom`) {\n\t\ttarget.logger.info(`๐Ÿงฎ`, state.type, state.key, `computing value`)\n\t\treturn state.get()\n\t}\n\tconst fallback =\n\t\tstate.default instanceof Function ? state.default() : state.default\n\ttarget.logger.info(\n\t\t`๐Ÿ’`,\n\t\t`atom`,\n\t\tstate.key,\n\t\t`could not find cached value; using default`,\n\t\tfallback,\n\t)\n\treturn state.default instanceof Function ? state.default() : state.default\n}\n","import type { Transactors, findState } from \"atom.io\"\nimport { findInStore } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { readOrComputeValue } from \"../read-or-compute-value\"\nimport { setAtomOrSelector } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { updateSelectorAtoms } from \"./update-selector-atoms\"\n\nexport const registerSelector = (\n\tselectorKey: string,\n\tstore: Store,\n): Transactors => ({\n\tget: (dependency) => {\n\t\tconst target = newest(store)\n\n\t\tconst dependencyState = withdraw(dependency, store)\n\t\tif (dependencyState === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${dependency.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t\t)\n\t\t}\n\t\tconst dependencyValue = readOrComputeValue(dependencyState, store)\n\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ”Œ`,\n\t\t\t`selector`,\n\t\t\tselectorKey,\n\t\t\t`registers dependency ( \"${dependency.key}\" =`,\n\t\t\tdependencyValue,\n\t\t\t`)`,\n\t\t)\n\n\t\ttarget.selectorGraph.set(\n\t\t\t{\n\t\t\t\tupstreamSelectorKey: dependency.key,\n\t\t\t\tdownstreamSelectorKey: selectorKey,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: dependency.key,\n\t\t\t},\n\t\t)\n\t\tupdateSelectorAtoms(selectorKey, dependency, store)\n\t\treturn dependencyValue\n\t},\n\tset: (WritableToken, newValue) => {\n\t\tconst state = withdraw(WritableToken, store)\n\t\tif (state === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${WritableToken.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t\t)\n\t\t}\n\t\tsetAtomOrSelector(state, newValue, store)\n\t},\n\tfind: ((token, key) => findInStore(token, key, store)) as typeof findState,\n})\n","export type Modify<T> = (thing: T) => T\n\nexport const become =\n\t<T>(nextVersionOfThing: Modify<T> | T) =>\n\t(originalThing: T): T =>\n\t\tnextVersionOfThing instanceof Function\n\t\t\t? nextVersionOfThing(\n\t\t\t\t\toriginalThing instanceof Function ? originalThing() : originalThing,\n\t\t\t )\n\t\t\t: nextVersionOfThing\n","import type { WritableToken } from \"atom.io\"\n\nimport { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\n\nexport type OperationProgress =\n\t| {\n\t\t\topen: false\n\t }\n\t| {\n\t\t\topen: true\n\t\t\tdone: Set<string>\n\t\t\tprev: Map<string, any>\n\t\t\ttime: number\n\t\t\ttoken: WritableToken<any>\n\t }\n\nexport const openOperation = (\n\ttoken: WritableToken<any>,\n\tstore: Store,\n): `rejection` | undefined => {\n\tif (store.operation.open) {\n\t\tstore.logger.error(\n\t\t\t`โŒ`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`failed to setState during a setState for \"${store.operation.token.key}\"`,\n\t\t)\n\t\treturn `rejection`\n\t}\n\tstore.operation = {\n\t\topen: true,\n\t\tdone: new Set(),\n\t\tprev: new Map(),\n\t\ttime: Date.now(),\n\t\ttoken,\n\t}\n\tstore.logger.info(\n\t\t`โญ•`,\n\t\ttoken.type,\n\t\ttoken.key,\n\t\t`operation start in store \"${store.config.name}\"${\n\t\t\tstore.transactionMeta === null\n\t\t\t\t? ``\n\t\t\t\t: ` ${store.transactionMeta.phase} \"${store.transactionMeta.update.key}\"`\n\t\t}`,\n\t)\n}\nexport const closeOperation = (store: Store): void => {\n\tif (store.operation.open) {\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ”ด`,\n\t\t\tstore.operation.token.type,\n\t\t\tstore.operation.token.key,\n\t\t\t`operation done in store \"${store.config.name}\"`,\n\t\t)\n\t}\n\tstore.operation = { open: false }\n\tstore.on.operationClose.next(store.operation)\n}\n\nexport const isDone = (key: string, store: Store): boolean => {\n\tif (!store.operation.open) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿž`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`isDone called outside of an operation. This is probably a bug.`,\n\t\t)\n\t\treturn true\n\t}\n\treturn store.operation.done.has(key)\n}\nexport const markDone = (key: string, store: Store): void => {\n\tif (!store.operation.open) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿž`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`markDone called outside of an operation. This is probably a bug.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.operation.done.add(key)\n}\n","import type { StateUpdate } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\n\nimport type { Atom, Selector } from \"..\"\n\nexport const emitUpdate = <T>(\n\tstate: Atom<T> | Selector<T>,\n\tupdate: StateUpdate<T>,\n\tstore: Store,\n): void => {\n\tstore.logger.info(\n\t\t`๐Ÿ“ข`,\n\t\tstate.type,\n\t\tstate.key,\n\t\t`went (`,\n\t\tupdate.oldValue,\n\t\t`->`,\n\t\tupdate.newValue,\n\t\t`) subscribers:`,\n\t\tstate.subject.subscribers,\n\t)\n\tstate.subject.next(update)\n}\n","import type { Atom } from \"..\"\nimport { evictCachedValue } from \"../caching\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Store } from \"../store\"\n\nexport const evictDownStream = <T>(atom: Atom<T>, store: Store): void => {\n\tconst downstreamKeys = store.selectorAtoms.getRelatedKeys(atom.key)\n\tstore.logger.info(\n\t\t`๐Ÿงน`,\n\t\tatom.type,\n\t\tatom.key,\n\t\tdownstreamKeys\n\t\t\t? `evicting ${downstreamKeys.size} states downstream:`\n\t\t\t: `no downstream states`,\n\t\tdownstreamKeys ?? `to evict`,\n\t)\n\tif (downstreamKeys) {\n\t\tif (store.operation.open) {\n\t\t\tstore.logger.info(\n\t\t\t\t`๐Ÿงน`,\n\t\t\t\tatom.type,\n\t\t\t\tatom.key,\n\t\t\t\t`[ ${[...store.operation.done].join(`, `)} ] already done`,\n\t\t\t)\n\t\t}\n\t\tfor (const key of downstreamKeys) {\n\t\t\tif (isDone(key, store)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tevictCachedValue(key, store)\n\t\t\tmarkDone(key, store)\n\t\t}\n\t}\n}\n","import type { KeyedStateUpdate, StateUpdate } from \"atom.io\"\n\nimport type { Atom } from \"..\"\nimport { newest } from \"../lineage\"\nimport { isTransceiver } from \"../mutable\"\nimport type { Store } from \"../store\"\n\nfunction shouldUpdateBeStowed(key: string, update: StateUpdate<any>): boolean {\n\t// do not stow updates that aren't json\n\tif (isTransceiver(update.newValue)) {\n\t\treturn false\n\t}\n\t// do not stow updates where the key contains ๐Ÿ‘โ€๐Ÿ—จ\n\tif (key.includes(`๐Ÿ‘โ€๐Ÿ—จ`)) {\n\t\treturn false\n\t}\n\treturn true\n}\n\nexport const stowUpdate = <T>(\n\tstate: Atom<T>,\n\tupdate: StateUpdate<T>,\n\tstore: Store,\n): void => {\n\tconst { key } = state\n\tconst target = newest(store)\n\tif (\n\t\ttarget.transactionMeta === null ||\n\t\ttarget.transactionMeta.phase !== `building`\n\t) {\n\t\tstore.logger.error(\n\t\t\t`๐Ÿž`,\n\t\t\t`atom`,\n\t\t\tkey,\n\t\t\t`stowUpdate called outside of a transaction. This is probably a bug.`,\n\t\t)\n\t\treturn\n\t}\n\tconst shouldStow = shouldUpdateBeStowed(key, update)\n\tif (!shouldStow) {\n\t\treturn\n\t}\n\tconst atomUpdate: KeyedStateUpdate<T> = { key, ...update }\n\tif (state.family) {\n\t\tatomUpdate.family = state.family\n\t}\n\ttarget.transactionMeta.update.updates.push(atomUpdate)\n\tstore.logger.info(\n\t\t`๐Ÿ“`,\n\t\t`atom`,\n\t\tkey,\n\t\t`stowed (`,\n\t\tupdate.oldValue,\n\t\t`->`,\n\t\tupdate.newValue,\n\t\t`)`,\n\t)\n}\n","import type { Atom } from \"..\"\nimport { isAtomDefault, markAtomAsNotDefault } from \"../atom\"\nimport { cacheValue } from \"../caching\"\nimport type { Transceiver } from \"../mutable\"\nimport { markDone } from \"../operation\"\nimport { readOrComputeValue } from \"../read-or-compute-value\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\nimport { copyMutableIfWithinTransaction } from \"./copy-mutable-in-transaction\"\nimport { emitUpdate } from \"./emit-update\"\nimport { evictDownStream } from \"./evict-downstream\"\nimport { stowUpdate } from \"./stow-update\"\n\nexport const setAtom = <T>(\n\tatom: Atom<T>,\n\tnext: T | ((oldValue: T) => T),\n\ttarget: Store,\n): void => {\n\tconst oldValue = readOrComputeValue(atom, target)\n\tlet newValue = copyMutableIfWithinTransaction(oldValue, atom, target)\n\tnewValue = become(next)(newValue)\n\ttarget.logger.info(`๐Ÿ“`, `atom`, atom.key, `set to`, newValue)\n\tnewValue = cacheValue(atom.key, newValue, atom.subject, target)\n\tif (isAtomDefault(atom.key, target)) {\n\t\tmarkAtomAsNotDefault(atom.key, target)\n\t}\n\tmarkDone(atom.key, target)\n\tevictDownStream(atom, target)\n\tconst update = { oldValue, newValue }\n\tif (target.transactionMeta === null) {\n\t\temitUpdate(atom, update, target)\n\t} else if (target.on.transactionApplying && target.parent) {\n\t\tstowUpdate(atom, update, target)\n\t\tif (atom.key.startsWith(`*`)) {\n\t\t\tconst mutableKey = atom.key.slice(1)\n\t\t\tconst mutable: Transceiver<any> = target.valueMap.get(mutableKey)\n\t\t\tmutable.do(update.newValue)\n\t\t}\n\t}\n}\n","import type { WritableState } from \"..\"\nimport type { Store } from \"../store\"\nimport { setAtom } from \"./set-atom\"\n\nexport const setAtomOrSelector = <T>(\n\tstate: WritableState<T>,\n\tvalue: T | ((oldValue: T) => T),\n\tstore: Store,\n): void => {\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tsetAtom(state, value, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\t\tstate.set(value)\n\t\t\tbreak\n\t}\n}\n","import { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\n\nexport type AtomKey<T> = string & { __atomKey?: never; __brand?: T }\nexport type SelectorKey<T> = string & { __selectorKey?: never; __brand?: T }\nexport type ReadonlySelectorKey<T> = string & {\n\t__readonlySelectorKey?: never\n\t__brand?: T\n}\n\nexport const isAtomKey = (key: string, store: Store): key is AtomKey<unknown> =>\n\tnewest(store).atoms.has(key)\nexport const isSelectorKey = (\n\tkey: string,\n\tstore: Store,\n): key is SelectorKey<unknown> => newest(store).selectors.has(key)\nexport const isReadonlySelectorKey = (\n\tkey: string,\n\tstore: Store,\n): key is ReadonlySelectorKey<unknown> =>\n\tnewest(store).readonlySelectors.has(key)\n\nexport type StateKey<T> = AtomKey<T> | ReadonlySelectorKey<T> | SelectorKey<T>\nexport const isStateKey = (\n\tkey: string,\n\tstore: Store,\n): key is StateKey<unknown> =>\n\tisAtomKey(key, store) ||\n\tisSelectorKey(key, store) ||\n\tisReadonlySelectorKey(key, store)\n","import type { AtomKey, ReadonlySelectorKey, SelectorKey } from \"../keys\"\nimport { isStateKey } from \"../keys\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const getSelectorDependencyKeys = (\n\tkey: string,\n\tstore: Store,\n): (\n\t| AtomKey<unknown>\n\t| ReadonlySelectorKey<unknown>\n\t| SelectorKey<unknown>\n)[] => {\n\tconst sources = newest(store)\n\t\t.selectorGraph.getRelationEntries({ downstreamSelectorKey: key })\n\t\t.filter(([_, { source }]) => source !== key)\n\t\t.map(([_, { source }]) => source)\n\t\t.filter((source) => isStateKey(source, store))\n\treturn sources\n}\n","import type { Selector, Store } from \"..\"\nimport type { AtomKey, StateKey } from \"../keys\"\nimport { isAtomKey } from \"../keys\"\nimport { getSelectorDependencyKeys } from \"./get-selector-dependency-keys\"\n\nexport const traceSelectorAtoms = (\n\tselectorKey: string,\n\tdirectDependencyKey: StateKey<unknown>,\n\tstore: Store,\n): AtomKey<unknown>[] => {\n\tconst rootKeys: AtomKey<unknown>[] = []\n\n\tconst indirectDependencyKeys = getSelectorDependencyKeys(\n\t\tdirectDependencyKey,\n\t\tstore,\n\t)\n\tlet depth = 0\n\twhile (indirectDependencyKeys.length > 0) {\n\t\t// biome-ignore lint/style/noNonNullAssertion: just checked length ^^^\n\t\tconst indirectDependencyKey = indirectDependencyKeys.shift()!\n\t\t++depth\n\t\tif (depth > 99999) {\n\t\t\tthrow new Error(\n\t\t\t\t`Maximum selector dependency depth exceeded (> 99999) in selector \"${selectorKey}\". This is likely due to a circular dependency.`,\n\t\t\t)\n\t\t}\n\n\t\tif (!isAtomKey(indirectDependencyKey, store)) {\n\t\t\tindirectDependencyKeys.push(\n\t\t\t\t...getSelectorDependencyKeys(indirectDependencyKey, store),\n\t\t\t)\n\t\t} else if (!rootKeys.includes(indirectDependencyKey)) {\n\t\t\trootKeys.push(indirectDependencyKey)\n\t\t}\n\t}\n\n\treturn rootKeys\n}\n\nexport const traceAllSelectorAtoms = (\n\tselector: Selector<any>,\n\tstore: Store,\n): AtomKey<unknown>[] => {\n\tconst selectorKey = selector.key\n\tconst directDependencyKeys = getSelectorDependencyKeys(selectorKey, store)\n\treturn directDependencyKeys.flatMap((depKey) =>\n\t\tisAtomKey(depKey, store)\n\t\t\t? depKey\n\t\t\t: traceSelectorAtoms(selectorKey, depKey, store),\n\t)\n}\n","import type { ReadonlySelectorToken, WritableToken } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { traceSelectorAtoms } from \"./trace-selector-atoms\"\n\nexport const updateSelectorAtoms = (\n\tselectorKey: string,\n\tdependency: ReadonlySelectorToken<unknown> | WritableToken<unknown>,\n\tstore: Store,\n): void => {\n\tconst target = newest(store)\n\tif (dependency.type === `atom` || dependency.type === `mutable_atom`) {\n\t\ttarget.selectorAtoms.set({\n\t\t\tselectorKey,\n\t\t\tatomKey: dependency.key,\n\t\t})\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ”`,\n\t\t\t`selector`,\n\t\t\tselectorKey,\n\t\t\t`discovers root atom \"${dependency.key}\"`,\n\t\t)\n\t} else {\n\t\tconst rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store)\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ”`,\n\t\t\t`selector`,\n\t\t\tselectorKey,\n\t\t\t`discovers root atoms: [ ${rootKeys\n\t\t\t\t.map((key) => `\"${key}\"`)\n\t\t\t\t.join(`, `)} ]`,\n\t\t)\n\t\tfor (const atomKey of rootKeys) {\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}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorOptions,\n\tReadonlySelectorToken,\n} from \"atom.io\"\n\nimport type { ReadonlySelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadonlySelector = <T>(\n\toptions: ReadonlySelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): ReadonlySelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\n\tconst { get, find } = registerSelector(options.key, store)\n\tconst getSelf = () => {\n\t\tconst value = options.get({ get, find })\n\t\tcacheValue(options.key, value, subject, store)\n\t\treturn value\n\t}\n\n\tconst readonlySelector: ReadonlySelector<T> = {\n\t\t...options,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlySelector(options, family, s),\n\t\tget: getSelf,\n\t\ttype: `readonly_selector`,\n\t\t...(family && { family }),\n\t}\n\ttarget.readonlySelectors.set(options.key, readonlySelector)\n\tconst initialValue = getSelf()\n\tstore.logger.info(\n\t\t`โœจ`,\n\t\treadonlySelector.type,\n\t\treadonlySelector.key,\n\t\t`=`,\n\t\tinitialValue,\n\t)\n\tconst token: ReadonlySelectorToken<T> = {\n\t\tkey: options.key,\n\t\ttype: `readonly_selector`,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\tstore.on.selectorCreation.next(token)\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tWritableSelectorOptions,\n\tWritableSelectorToken,\n} from \"atom.io\"\n\nimport type { WritableSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { markDone } from \"../operation\"\nimport { become } from \"../set-state/become\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createWritableSelector = <T>(\n\toptions: WritableSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): WritableSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst transactors = registerSelector(options.key, store)\n\tconst { find, get } = transactors\n\tconst readonlyTransactors = { find, get }\n\n\tconst getSelf = () => {\n\t\tconst value = options.get(readonlyTransactors)\n\t\tcacheValue(options.key, value, subject, newest(store))\n\t\treturn value\n\t}\n\n\tconst setSelf = (next: T | ((oldValue: T) => T)): void => {\n\t\tconst oldValue = getSelf()\n\t\tconst newValue = become(next)(oldValue)\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ“`,\n\t\t\t`selector`,\n\t\t\toptions.key,\n\t\t\t`set (`,\n\t\t\toldValue,\n\t\t\t`->`,\n\t\t\tnewValue,\n\t\t\t`)`,\n\t\t)\n\t\tcacheValue(options.key, newValue, subject, store)\n\t\tmarkDone(options.key, store)\n\t\tif (target.transactionMeta === null) {\n\t\t\tsubject.next({ newValue, oldValue })\n\t\t}\n\t\toptions.set(transactors, newValue)\n\t}\n\tconst mySelector: WritableSelector<T> = {\n\t\t...options,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritableSelector(options, family, s),\n\t\tget: getSelf,\n\t\tset: setSelf,\n\t\ttype: `selector`,\n\t\t...(family && { family }),\n\t}\n\ttarget.selectors.set(options.key, mySelector)\n\tconst initialValue = getSelf()\n\tstore.logger.info(`โœจ`, mySelector.type, mySelector.key, `=`, initialValue)\n\tconst token: WritableSelectorToken<T> = {\n\t\tkey: options.key,\n\t\ttype: `selector`,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\tstore.on.selectorCreation.next(token)\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorOptions,\n\tReadonlySelectorToken,\n\tWritableSelectorOptions,\n\tWritableSelectorToken,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { createReadonlySelector } from \"./create-readonly-selector\"\nimport { createWritableSelector } from \"./create-writable-selector\"\n\nexport function createStandaloneSelector<T>(\n\toptions: WritableSelectorOptions<T>,\n\tstore: Store,\n): WritableSelectorToken<T>\nexport function createStandaloneSelector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n\tstore: Store,\n): ReadonlySelectorToken<T>\nexport function createStandaloneSelector<T>(\n\toptions: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,\n\tstore: Store,\n): ReadonlySelectorToken<T> | WritableSelectorToken<T> {\n\tconst isWritable = `set` in options\n\n\tif (isWritable) {\n\t\treturn createWritableSelector(options, undefined, store)\n\t}\n\treturn createReadonlySelector(options, undefined, store)\n}\n","import type { ReadonlySelectorToken, WritableSelectorToken } from \"atom.io\"\n\nimport { newest } from \"..\"\nimport type { Store } from \"..\"\n\nexport function deleteSelector(\n\tselectorToken: ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>,\n\tstore: Store,\n): void {\n\tconst target = newest(store)\n\tconst { key } = selectorToken\n\tswitch (selectorToken.type) {\n\t\tcase `selector`:\n\t\t\ttarget.selectors.delete(key)\n\t\t\tbreak\n\t\tcase `readonly_selector`:\n\t\t\ttarget.readonlySelectors.delete(key)\n\t\t\tbreak\n\t}\n\ttarget.valueMap.delete(key)\n\ttarget.selectorAtoms.delete(key)\n\tconst downstreamTokens = target.selectorGraph\n\t\t.getRelationEntries({ upstreamSelectorKey: key })\n\t\t.filter(([_, { source }]) => source === key)\n\t\t.map(\n\t\t\t([downstreamSelectorKey]) =>\n\t\t\t\ttarget.selectors.get(downstreamSelectorKey) ??\n\t\t\t\ttarget.readonlySelectors.get(downstreamSelectorKey),\n\t\t)\n\tfor (const downstreamToken of downstreamTokens) {\n\t\tif (downstreamToken) {\n\t\t\tdeleteSelector(downstreamToken, store)\n\t\t}\n\t}\n\ttarget.selectorGraph.delete(key)\n\tstore.logger.info(`๐Ÿ”ฅ`, selectorToken.type, `${key}`, `deleted`)\n}\n","import type { ReadableState } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const recallState = <T>(state: ReadableState<T>, store: Store): T => {\n\tconst target = newest(store)\n\tif (!target.operation.open) {\n\t\treturn target.valueMap.get(state.key)\n\t}\n\treturn target.operation.prev.get(state.key)\n}\n","import type { Selector } from \"..\"\nimport { newest } from \"../lineage\"\nimport { readOrComputeValue } from \"../read-or-compute-value\"\nimport { traceAllSelectorAtoms } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { recallState } from \"./recall-state\"\n\nexport const subscribeToRootAtoms = <T>(\n\tselector: Selector<T>,\n\tstore: Store,\n): (() => void)[] | null => {\n\tconst target = newest(store)\n\tconst dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(\n\t\t(atomKey) => {\n\t\t\tconst atom = target.atoms.get(atomKey)\n\t\t\tif (atom === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Atom \"${atomKey}\", a dependency of selector \"${selector.key}\", not found in store \"${store.config.name}\".`,\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn atom.subject.subscribe(\n\t\t\t\t`${selector.type}:${selector.key}`,\n\t\t\t\t(atomChange) => {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`๐Ÿ“ข`,\n\t\t\t\t\t\tselector.type,\n\t\t\t\t\t\tselector.key,\n\t\t\t\t\t\t`root`,\n\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t`went`,\n\t\t\t\t\t\tatomChange.oldValue,\n\t\t\t\t\t\t`->`,\n\t\t\t\t\t\tatomChange.newValue,\n\t\t\t\t\t)\n\t\t\t\t\tconst oldValue = recallState(selector, target)\n\t\t\t\t\tconst newValue = readOrComputeValue(selector, target)\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`โœจ`,\n\t\t\t\t\t\tselector.type,\n\t\t\t\t\t\tselector.key,\n\t\t\t\t\t\t`went`,\n\t\t\t\t\t\toldValue,\n\t\t\t\t\t\t`->`,\n\t\t\t\t\t\tnewValue,\n\t\t\t\t\t)\n\t\t\t\t\tselector.subject.next({ newValue, oldValue })\n\t\t\t\t},\n\t\t\t)\n\t\t},\n\t)\n\treturn dependencySubscriptions\n}\n","import type { ReadableToken, UpdateHandler } from \"atom.io\"\nimport type { Store } from \"../store\"\nimport { withdraw, withdrawNewFamilyMember } from \"../store\"\nimport { subscribeToRootAtoms } from \"./subscribe-to-root-atoms\"\n\nexport function subscribeToState<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string,\n\tstore: Store,\n): () => void {\n\tconst state =\n\t\twithdraw<T>(token, store) ?? withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.logger.info(`๐Ÿ‘€`, state.type, state.key, `Adding subscription \"${key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` && state.type !== `mutable_atom`\n\t\t\t? subscribeToRootAtoms(state, store)\n\t\t\t: null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`๐Ÿ™ˆ`,\n\t\t\t\t\t\tstate.type,\n\t\t\t\t\t\tstate.key,\n\t\t\t\t\t\t`Removing subscription \"${key}\"`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`๐Ÿ™ˆ`,\n\t\t\t\t\t\tstate.type,\n\t\t\t\t\t\tstate.key,\n\t\t\t\t\t\t`Removing subscription \"${key}\"`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n","import type { TimelineManageable, TimelineToken, TimelineUpdate } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { withdraw } from \"atom.io/internal\"\n\nexport const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(\n\ttoken: TimelineToken<ManagedAtom>,\n\thandleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void,\n\tkey: string,\n\tstore: Store,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.logger.info(`๐Ÿ‘€`, `timeline`, token.key, `Adding subscription \"${key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ™ˆ`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Removing subscription \"${key}\" from timeline`,\n\t\t)\n\t\tunsubscribe()\n\t}\n}\n","import type { TransactionToken, TransactionUpdateHandler, ฦ’n } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { withdraw } from \"atom.io/internal\"\n\nexport const subscribeToTransaction = <ฦ’ extends ฦ’n>(\n\ttoken: TransactionToken<ฦ’>,\n\thandleUpdate: TransactionUpdateHandler<ฦ’>,\n\tkey: string,\n\tstore: Store,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.logger.info(\n\t\t`๐Ÿ‘€`,\n\t\t`transaction`,\n\t\ttoken.key,\n\t\t`Adding subscription \"${key}\"`,\n\t)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ™ˆ`,\n\t\t\t`transaction`,\n\t\t\ttoken.key,\n\t\t\t`Removing subscription \"${key}\"`,\n\t\t)\n\t\tunsubscribe()\n\t}\n}\n","import type { FamilyMetadata, MutableAtomToken, RegularAtomToken } from \"atom.io\"\nimport { getState, setState } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"..\"\nimport { newest, subscribeToState, subscribeToTimeline } from \"..\"\nimport { createRegularAtom } from \"../atom\"\nimport type { Transceiver } from \"./transceiver\"\n\n/**\n * @internal Give the tracker a transceiver state and a store, and it will\n * subscribe to the transceiver's inner value. When the inner value changes,\n * the tracker will update its own state to reflect the change.\n */\nexport class Tracker<Mutable extends Transceiver<any>> {\n\tprivate Update: Mutable extends Transceiver<infer Signal> ? Signal : never\n\n\tprivate initializeState(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store,\n\t): RegularAtomToken<typeof this.Update | null> {\n\t\tconst latestUpdateStateKey = `*${mutableState.key}`\n\t\tstore.atoms.delete(latestUpdateStateKey)\n\t\tstore.valueMap.delete(latestUpdateStateKey)\n\t\tconst familyMetaData: FamilyMetadata | undefined = mutableState.family\n\t\t\t? {\n\t\t\t\t\tkey: `*${mutableState.family.key}`,\n\t\t\t\t\tsubKey: mutableState.family.subKey,\n\t\t\t }\n\t\t\t: undefined\n\t\tconst latestUpdateState = createRegularAtom<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>(\n\t\t\t{\n\t\t\t\tkey: latestUpdateStateKey,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\tfamilyMetaData,\n\t\t\tstore,\n\t\t)\n\t\tif (store.parent?.valueMap.has(latestUpdateStateKey)) {\n\t\t\tconst parentValue = store.parent.valueMap.get(latestUpdateStateKey)\n\t\t\tstore.valueMap.set(latestUpdateStateKey, parentValue)\n\t\t}\n\n\t\treturn latestUpdateState\n\t}\n\n\tprivate unsubscribeFromInnerValue: () => void\n\tprivate unsubscribeFromState: () => void\n\tprivate observeCore(\n\t\tmutableState: MutableAtomToken<Mutable, any>,\n\t\tlatestUpdateState: RegularAtomToken<typeof this.Update | null>,\n\t\tstore: Store,\n\t): void {\n\t\tconst originalInnerValue = getState(mutableState, store)\n\t\tconst target = newest(store)\n\t\tthis.unsubscribeFromInnerValue = originalInnerValue.subscribe(\n\t\t\t`tracker:${store.config.name}:${\n\t\t\t\ttarget.transactionMeta === null\n\t\t\t\t\t? `main`\n\t\t\t\t\t: target.transactionMeta.update.key\n\t\t\t}`,\n\t\t\t(update) => {\n\t\t\t\tif (target.operation.open) {\n\t\t\t\t\tconst unsubscribe = target.on.operationClose.subscribe(\n\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\tsetState(latestUpdateState, update, target)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tsetState(mutableState, (current) => current, target)\n\t\t\t\t\tsetState(latestUpdateState, update, target)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tthis.unsubscribeFromState = subscribeToState(\n\t\t\tmutableState,\n\t\t\t(update) => {\n\t\t\t\tif (update.newValue !== update.oldValue) {\n\t\t\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\t\t\tconst target = newest(store)\n\t\t\t\t\tthis.unsubscribeFromInnerValue = update.newValue.subscribe(\n\t\t\t\t\t\t`tracker:${store.config.name}:${\n\t\t\t\t\t\t\ttarget.transactionMeta === null\n\t\t\t\t\t\t\t\t? `main`\n\t\t\t\t\t\t\t\t: target.transactionMeta.update.key\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\tif (target.operation.open) {\n\t\t\t\t\t\t\t\tconst unsubscribe = target.on.operationClose.subscribe(\n\t\t\t\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\t\t\tsetState(latestUpdateState, update, target)\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetState(mutableState, (current) => current, target)\n\t\t\t\t\t\t\t\tsetState(latestUpdateState, update, target)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t\t`${store.config.name}: tracker observing inner value`,\n\t\t\tstore,\n\t\t)\n\t}\n\n\tprivate updateCore<Core extends Transceiver<any>>(\n\t\tmutableState: MutableAtomToken<Core, Json.Serializable>,\n\t\tlatestUpdateState: RegularAtomToken<typeof this.Update | null>,\n\t\tstore: Store,\n\t): void {\n\t\tsubscribeToState(\n\t\t\tlatestUpdateState,\n\t\t\t({ newValue, oldValue }) => {\n\t\t\t\tconst timelineId = store.timelineAtoms.getRelatedKey(\n\t\t\t\t\tlatestUpdateState.key,\n\t\t\t\t)\n\t\t\t\tif (timelineId) {\n\t\t\t\t\tconst timelineData = store.timelines.get(timelineId)\n\t\t\t\t\tif (timelineData?.timeTraveling) {\n\t\t\t\t\t\tconst unsubscribe = subscribeToTimeline(\n\t\t\t\t\t\t\t{ key: timelineId, type: `timeline` },\n\t\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\tsetState(\n\t\t\t\t\t\t\t\t\tmutableState,\n\t\t\t\t\t\t\t\t\t(transceiver) => {\n\t\t\t\t\t\t\t\t\t\tif (update === `redo` && newValue) {\n\t\t\t\t\t\t\t\t\t\t\ttransceiver.do(newValue)\n\t\t\t\t\t\t\t\t\t\t} else if (update === `undo` && oldValue) {\n\t\t\t\t\t\t\t\t\t\t\ttransceiver.undo(oldValue)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn transceiver\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t`${mutableState.key}: tracker observing timeline`,\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t\t\tlatestUpdateState.key,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\tconst mutable = getState(mutableState, store)\n\t\t\t\t\t\t// debugger\n\t\t\t\t\t\tconst updateNumber =\n\t\t\t\t\t\t\tnewValue === null ? -1 : mutable.getUpdateNumber(newValue)\n\t\t\t\t\t\tconst eventOffset = updateNumber - mutable.cacheUpdateNumber\n\t\t\t\t\t\tif (newValue && eventOffset === 1) {\n\t\t\t\t\t\t\t// โ— new:\"0=add:\\\"myHand\\\"\",old:\"0=add:\\\"deckId\\\"\"\n\t\t\t\t\t\t\tsetState(\n\t\t\t\t\t\t\t\tmutableState,\n\t\t\t\t\t\t\t\t(transceiver) => (transceiver.do(newValue), transceiver),\n\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t},\n\t\t\t`${store.config.name}: tracker observing latest update`,\n\t\t\tstore,\n\t\t)\n\t}\n\n\tpublic mutableState: MutableAtomToken<Mutable, Json.Serializable>\n\tpublic latestUpdateState: RegularAtomToken<typeof this.Update | null>\n\n\tpublic dispose: () => void\n\n\tpublic constructor(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store,\n\t) {\n\t\tthis.mutableState = mutableState\n\t\tconst target = newest(store)\n\t\tthis.latestUpdateState = this.initializeState(mutableState, target)\n\t\tthis.observeCore(mutableState, this.latestUpdateState, target)\n\t\tthis.updateCore(mutableState, this.latestUpdateState, target)\n\t\ttarget.trackers.set(mutableState.key, this)\n\t\tthis.dispose = () => {\n\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\tthis.unsubscribeFromState()\n\t\t\ttarget.trackers.delete(mutableState.key)\n\t\t}\n\t}\n}\n","import type {\n\tMutableAtomFamily,\n\tMutableAtomFamilyOptions,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n} from \"atom.io\"\nimport type { FamilyMetadata } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJsonFamily } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport { createMutableAtom } from \"../mutable\"\nimport { deposit, withdraw } from \"../store\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { FamilyTracker } from \"./tracker-family\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends string,\n>(\n\toptions: MutableAtomFamilyOptions<T, J, K>,\n\tstore: Store,\n): MutableAtomFamily<T, J, K> {\n\tconst subject = new Subject<MutableAtomToken<T, J>>()\n\tconst atomFamily: MutableAtomFamily<T, J, K> = Object.assign(\n\t\t(key: K): MutableAtomToken<T, J> => {\n\t\t\tconst subKey = stringifyJson(key)\n\t\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\t\tconst fullKey = `${options.key}(${subKey})`\n\t\t\tconst existing = withdraw({ key: fullKey, type: `mutable_atom` }, store)\n\t\t\tlet token: MutableAtomToken<T, J>\n\t\t\tif (existing) {\n\t\t\t\ttoken = deposit(existing)\n\t\t\t} else {\n\t\t\t\tconst individualOptions: MutableAtomOptions<T, J> = {\n\t\t\t\t\tkey: fullKey,\n\t\t\t\t\tdefault: () => options.default(key),\n\t\t\t\t\ttoJson: options.toJson,\n\t\t\t\t\tfromJson: options.fromJson,\n\t\t\t\t\tmutable: true,\n\t\t\t\t}\n\t\t\t\tif (options.effects) {\n\t\t\t\t\tindividualOptions.effects = options.effects(key)\n\t\t\t\t}\n\n\t\t\t\ttoken = createMutableAtom(individualOptions, family, store)\n\n\t\t\t\tsubject.next(token)\n\t\t\t}\n\t\t\treturn token\n\t\t},\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `mutable_atom_family`,\n\t\t\tsubject,\n\t\t\tinstall: (store: Store) => createMutableAtomFamily(options, store),\n\t\t\ttoJson: options.toJson,\n\t\t\tfromJson: options.fromJson,\n\t\t} as const,\n\t)\n\n\tconst target = newest(store)\n\ttarget.families.set(options.key, atomFamily)\n\tselectJsonFamily(atomFamily, options, store)\n\tnew FamilyTracker(atomFamily, store)\n\treturn atomFamily\n}\n","import type { MutableAtomFamily, RegularAtomFamily } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport { createRegularAtomFamily } from \"../families\"\nimport type { Store } from \"../store\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport class FamilyTracker<\n\tCore extends Transceiver<any>,\n\tFamilyMemberKey extends Json.Serializable,\n> {\n\tprivate readonly Update: Core extends Transceiver<infer Signal>\n\t\t? Signal\n\t\t: never\n\n\tpublic readonly findLatestUpdateState: RegularAtomFamily<\n\t\ttypeof this.Update | null,\n\t\tFamilyMemberKey\n\t>\n\tpublic readonly findMutableState: MutableAtomFamily<Core, any, FamilyMemberKey>\n\n\tpublic constructor(\n\t\tfindMutableState: MutableAtomFamily<Core, any, FamilyMemberKey>,\n\t\tstore: Store,\n\t) {\n\t\tthis.findLatestUpdateState = createRegularAtomFamily<\n\t\t\ttypeof this.Update | null,\n\t\t\tFamilyMemberKey\n\t\t>(\n\t\t\t{\n\t\t\t\tkey: `*${findMutableState.key}`,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\tthis.findMutableState = findMutableState\n\t\tthis.findMutableState.subject.subscribe(\n\t\t\t`store=${store.config.name}::tracker-atom-family`,\n\t\t\t(atomToken) => {\n\t\t\t\tif (atomToken.family) {\n\t\t\t\t\tconst key = parseJson(atomToken.family.subKey) as FamilyMemberKey\n\t\t\t\t\tthis.findLatestUpdateState(key)\n\t\t\t\t\tnew Tracker<Core>(atomToken, store)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tthis.findLatestUpdateState.subject.subscribe(\n\t\t\t`store=${store.config.name}::tracker-atom-family`,\n\t\t\t(atomToken) => {\n\t\t\t\tif (atomToken.family) {\n\t\t\t\t\tconst key = parseJson(atomToken.family.subKey) as FamilyMemberKey\n\t\t\t\t\tconst mutableAtomToken = this.findMutableState(key)\n\t\t\t\t\tnew Tracker<Core>(mutableAtomToken, store)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tRegularAtomFamily,\n\tRegularAtomFamilyOptions,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createRegularAtom } from \"../atom\"\nimport { newest } from \"../lineage\"\nimport { deposit, withdraw } from \"../store\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createRegularAtomFamily<T, K extends Json.Serializable>(\n\toptions: RegularAtomFamilyOptions<T, K>,\n\tstore: Store,\n): RegularAtomFamily<T, K> {\n\tconst subject = new Subject<RegularAtomToken<T>>()\n\tconst atomFamily: RegularAtomFamily<T, K> = Object.assign(\n\t\t(key: K): RegularAtomToken<any> => {\n\t\t\tconst subKey = stringifyJson(key)\n\t\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\t\tconst fullKey = `${options.key}(${subKey})`\n\t\t\tconst existing = withdraw({ key: fullKey, type: `atom` }, store)\n\t\t\tlet token: RegularAtomToken<any>\n\t\t\tif (existing) {\n\t\t\t\ttoken = deposit(existing)\n\t\t\t} else {\n\t\t\t\tconst individualOptions: RegularAtomOptions<any> = {\n\t\t\t\t\tkey: fullKey,\n\t\t\t\t\tdefault:\n\t\t\t\t\t\toptions.default instanceof Function\n\t\t\t\t\t\t\t? options.default(key)\n\t\t\t\t\t\t\t: options.default,\n\t\t\t\t}\n\t\t\t\tif (options.effects) {\n\t\t\t\t\tindividualOptions.effects = options.effects(key)\n\t\t\t\t}\n\t\t\t\ttoken = createRegularAtom(individualOptions, family, store)\n\t\t\t\tsubject.next(token)\n\t\t\t}\n\t\t\treturn token\n\t\t},\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `atom_family`,\n\t\t\tsubject,\n\t\t\tinstall: (store: Store) => createRegularAtomFamily(options, store),\n\t\t} as const,\n\t)\n\tconst target = newest(store)\n\ttarget.families.set(options.key, atomFamily)\n\treturn atomFamily\n}\n","import type {\n\tMutableAtomFamily,\n\tMutableAtomFamilyOptions,\n\tRegularAtomFamily,\n\tRegularAtomFamilyOptions,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { type Transceiver, createMutableAtomFamily } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { createRegularAtomFamily } from \"./create-regular-atom-family\"\n\nexport function createAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(\n\toptions: MutableAtomFamilyOptions<T, J, K>,\n\tstore: Store,\n): MutableAtomFamily<T, J, K>\nexport function createAtomFamily<T, K extends Json.Serializable>(\n\toptions: RegularAtomFamilyOptions<T, K>,\n\tstore: Store,\n): RegularAtomFamily<T, K>\nexport function createAtomFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t| RegularAtomFamilyOptions<T, K>,\n\tstore: Store,\n): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\tconst isMutable = `mutable` in options\n\n\tif (isMutable) {\n\t\treturn createMutableAtomFamily(options, store)\n\t}\n\treturn createRegularAtomFamily<T, K>(options, store)\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorFamily,\n\tReadonlySelectorFamilyOptions,\n\tReadonlySelectorToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport { createReadonlySelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createReadonlySelectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n\tstore: Store,\n): ReadonlySelectorFamily<T, K> {\n\tconst subject = new Subject<ReadonlySelectorToken<T>>()\n\tconst readonlySelectorFamily = Object.assign(\n\t\t(key: K): ReadonlySelectorToken<T> => {\n\t\t\tconst target = newest(store)\n\t\t\tconst subKey = stringifyJson(key)\n\t\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\t\tconst fullKey = `${options.key}(${subKey})`\n\t\t\tconst existing = target.readonlySelectors.get(fullKey)\n\t\t\tif (existing) {\n\t\t\t\treturn deposit(existing)\n\t\t\t}\n\t\t\treturn createReadonlySelector(\n\t\t\t\t{\n\t\t\t\t\tkey: fullKey,\n\t\t\t\t\tget: options.get(key),\n\t\t\t\t},\n\t\t\t\tfamily,\n\t\t\t\tstore,\n\t\t\t) as ReadonlySelectorToken<T>\n\t\t},\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `readonly_selector_family`,\n\t\t\tsubject,\n\t\t\tinstall: (store: Store) => createReadonlySelectorFamily(options, store),\n\t\t} as const,\n\t) as ReadonlySelectorFamily<T, K>\n\tstore.families.set(options.key, readonlySelectorFamily)\n\treturn readonlySelectorFamily\n}\n","import type {\n\tFamilyMetadata,\n\tWritableSelectorFamily,\n\tWritableSelectorFamilyOptions,\n\tWritableSelectorToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createWritableSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createWritableSelectorFamily<T, K extends Json.Serializable>(\n\toptions: WritableSelectorFamilyOptions<T, K>,\n\tstore: Store,\n): WritableSelectorFamily<T, K> {\n\tconst subject = new Subject<WritableSelectorToken<T>>()\n\n\tconst selectorFamily = Object.assign(\n\t\t(key: K): WritableSelectorToken<T> => {\n\t\t\tconst subKey = stringifyJson(key)\n\t\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\t\tconst fullKey = `${options.key}(${subKey})`\n\t\t\tconst existing = store.selectors.get(fullKey)\n\t\t\tif (existing) {\n\t\t\t\treturn deposit(existing)\n\t\t\t}\n\t\t\tconst token = createWritableSelector(\n\t\t\t\t{\n\t\t\t\t\tkey: fullKey,\n\t\t\t\t\tget: options.get(key),\n\t\t\t\t\tset: options.set(key),\n\t\t\t\t},\n\t\t\t\tfamily,\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tsubject.next(token)\n\t\t\treturn token\n\t\t},\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `selector_family`,\n\t\t\tsubject,\n\t\t\tinstall: (store: Store) => createWritableSelectorFamily(options, store),\n\t\t} as const,\n\t) as WritableSelectorFamily<T, K>\n\tstore.families.set(options.key, selectorFamily)\n\treturn selectorFamily\n}\n","import type {\n\tReadonlySelectorFamily,\n\tReadonlySelectorFamilyOptions,\n\tWritableSelectorFamily,\n\tWritableSelectorFamilyOptions,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { createReadonlySelectorFamily } from \"./create-readonly-selector-family\"\nimport { createWritableSelectorFamily } from \"./create-writable-selector-family\"\n\nexport function createSelectorFamily<T, K extends Json.Serializable>(\n\toptions: WritableSelectorFamilyOptions<T, K>,\n\tstore: Store,\n): WritableSelectorFamily<T, K>\nexport function createSelectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n\tstore: Store,\n): ReadonlySelectorFamily<T, K>\nexport function createSelectorFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| ReadonlySelectorFamilyOptions<T, K>\n\t\t| WritableSelectorFamilyOptions<T, K>,\n\tstore: Store,\n): ReadonlySelectorFamily<T, K> | WritableSelectorFamily<T, K> {\n\tconst isWritable = `set` in options\n\n\tif (isWritable) {\n\t\treturn createWritableSelectorFamily(options, store)\n\t}\n\treturn createReadonlySelectorFamily(options, store)\n}\n","import type { MutableAtomFamily, WritableSelectorFamily } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonFamily = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends string,\n>(\n\tmutableAtomFamily: MutableAtomFamily<Core, SerializableCore, Key>,\n\tstore: Store,\n): WritableSelectorFamily<SerializableCore, Key> => {\n\tconst target = newest(store)\n\tconst key = `${mutableAtomFamily.key}:JSON`\n\tconst jsonFamily: WritableSelectorFamily<SerializableCore, Key> =\n\t\ttarget.families.get(key) as WritableSelectorFamily<SerializableCore, Key>\n\treturn jsonFamily\n}\n","import type { MutableAtomToken, WritableSelectorToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonToken = <\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): WritableSelectorToken<SerializableCore> => {\n\tconst key = mutableAtomToken.family\n\t\t? `${mutableAtomToken.family.key}:JSON(${mutableAtomToken.family.subKey})`\n\t\t: `${mutableAtomToken.key}:JSON`\n\tconst jsonToken: WritableSelectorToken<SerializableCore> = {\n\t\ttype: `selector`,\n\t\tkey,\n\t}\n\tif (mutableAtomToken.family) {\n\t\tjsonToken.family = {\n\t\t\tkey: `${mutableAtomToken.family.key}:JSON`,\n\t\t\tsubKey: mutableAtomToken.family.subKey,\n\t\t}\n\t}\n\treturn jsonToken\n}\n","import type { MutableAtomToken, RegularAtomToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport type { Signal, Transceiver } from \"./transceiver\"\n\nexport const getUpdateToken = <\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): RegularAtomToken<Signal<Core>> => {\n\tconst key = `*${mutableAtomToken.key}`\n\tconst updateToken: RegularAtomToken<Signal<Core>> = { type: `atom`, key }\n\tif (mutableAtomToken.family) {\n\t\tupdateToken.family = {\n\t\t\tkey: `*${mutableAtomToken.family.key}`,\n\t\t\tsubKey: mutableAtomToken.family.subKey,\n\t\t}\n\t}\n\treturn updateToken\n}\n","import type { AtomFamily, MutableAtomFamily } from \"atom.io\"\n\nimport type { Atom, MutableAtom } from \"..\"\n\nexport function isMutable(atom: Atom<any>): atom is MutableAtom<any, any>\nexport function isMutable(\n\tfamily: AtomFamily<any, any>,\n): family is MutableAtomFamily<any, any, any>\nexport function isMutable(\n\tatomOrTokenOrFamily: Atom<any> | AtomFamily<any, any>,\n): boolean {\n\treturn (\n\t\tatomOrTokenOrFamily.type === `mutable_atom` ||\n\t\tatomOrTokenOrFamily.type === `mutable_atom_family`\n\t)\n}\n","import type { Json } from \"atom.io/json\"\n\nexport interface Transceiver<Signal extends Json.Serializable> {\n\tdo: (update: Signal) => void\n\tundo: (update: Signal) => void\n\tsubscribe: (key: string, fn: (update: Signal) => void) => () => void\n\tcacheUpdateNumber: number\n\tgetUpdateNumber: (update: Signal) => number\n}\n\nexport function isTransceiver(\n\tvalue: unknown,\n): value is Transceiver<Json.Serializable> {\n\treturn (\n\t\ttypeof value === `object` &&\n\t\tvalue !== null &&\n\t\t`do` in value &&\n\t\t`undo` in value &&\n\t\t`subscribe` in value\n\t)\n}\n\nexport type TransceiverMode = `playback` | `record` | `transaction`\n\nexport type Signal<TVR extends Transceiver<any>> = TVR extends Transceiver<\n\tinfer Signal\n>\n\t? Signal\n\t: never\n\n/*\nA transceiver may also keep a list of updates that have been applied to it.\nThis is useful for undo/redo functionality, especially in the context of\nrevising history. It is a good idea to accept a cache limit in your \nconstructor, and overwrite old updates. Here's an example of how we \nmight set that up:\n\nmyTransceiver = Transceiver {\n\tcacheUpdateNumber: number = 27\n\tcacheIdx: number = 1\n\tcacheLimit: number = 3\n\tcache: Array<Update> = [\n\t\t26=add:\"x\"\n\t\t27=del:\"x\" (current)\n\t\t25=add:\"y\"\n\t]\n}\n\nCONFIRM/NO-OP\nUpdate `27=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 27, update = `del:\"x\"`]\t\n- updateOffset = updateNumber - cacheUpdateNumber // 0\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // 1\n- update === cache.get(eventIdx) // true\n- return null // ๐Ÿ‘\n\nEXPECTED UPDATE\nUpdate `28=add:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 28, update = `add:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 1\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // true (we're ready to apply this update)\n- cacheIdx += eventOffset // 2\n- cacheIdx %= cacheLimit // 2\n- cache[cacheIdx] = update // cache = <{ 0 => add:\"x\" }>\n- return null // ๐Ÿ‘\n\nUNEXPECTED UPDATE\nUpdate `29=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 29, update = `del:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 2\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // false (we're NOT ready to apply this update)\n- updateIdx := cacheIdx + updateOffset // 3\n- updateIdx %= cacheLimit // 0\n- cache[updateIdx] = update // cache = <{ 0 => del:\"x\" }> \n- expectedUpdateNumber = cacheUpdateNumber + 1 // 28\n- return expectedUpdateNumber // ๐Ÿคจ๐Ÿ‘‚\n\nSUCCESSFUL ROLLBACK UPDATE\nUpdate `25=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 25, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -2\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // -1\n- eventIdx %= cacheLimit // 2\n- update === cache[eventIdx] // false (we're rolling back)\n- done := false\n- update := cache[cacheIdx] // update = `del:\"x\"`\n- undo(update) // myTransceiver.undo(`del:\"x\"`)\n- while (!done) {\n- \tcacheIdx -= 1 // 0, -1\n- \tcacheIdx %= cacheLimit // 0, 2\n- \tupdate = cache[cacheIdx] // update = `add:\"y\"`, `add:\"x\"`\n- \tundo(update) // myTransceiver.undo(`add:\"y\"`), myTransceiver.undo(`add:\"x\"`)\n- \tdone = cacheIdx === eventIdx // false, true\n- }\n- do(update) // myTransceiver.do(`add:\"z\"`)\n- return null // ๐Ÿ‘\n\nUNSUCCESSFUL ROLLBACK UPDATE\nUpdate `24=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 24, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -3\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // 3 < 3 // false (we don't remember this update)\n- return `OUT_OF_RANGE` // ๐Ÿ˜ตโ€๐Ÿ’ซ๐Ÿ‘‚\n\n*/\n","import type {\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport type { RegularAtom } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport { markAtomAsDefault } from \"./is-default\"\n\nexport function createRegularAtom<T>(\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): RegularAtomToken<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 existing = target.atoms.get(options.key)\n\tif (existing && existing.type === `atom`) {\n\t\tstore.logger.error(\n\t\t\t`โŒ`,\n\t\t\t`atom`,\n\t\t\toptions.key,\n\t\t\t`Tried to create atom, but it already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: RegularAtom<T> = {\n\t\t...options,\n\t\ttype: `atom`,\n\t\tinstall: (store: Store) => {\n\t\t\tstore.logger.info(\n\t\t\t\t`๐Ÿ› ๏ธ`,\n\t\t\t\t`atom`,\n\t\t\t\toptions.key,\n\t\t\t\t`installing in store \"${store.config.name}\"`,\n\t\t\t)\n\t\t\treturn createRegularAtom(options, family, store)\n\t\t},\n\t\tsubject,\n\t} as const\n\tif (family) {\n\t\tnewAtom.family = family\n\t}\n\tlet initialValue = options.default\n\tif (options.default instanceof Function) {\n\t\tinitialValue = options.default()\n\t}\n\ttarget.atoms.set(newAtom.key, newAtom)\n\tmarkAtomAsDefault(options.key, store)\n\tcacheValue(options.key, initialValue, subject, target)\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\tsetSelf: (next) => setState(token, next, store),\n\t\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\t\tsubscribeToState(token, handle, `effect[${effectIndex}]`, store),\n\t\t\t})\n\t\t\tif (cleanup) {\n\t\t\t\tcleanupFunctions.push(cleanup)\n\t\t\t}\n\t\t\t++effectIndex\n\t\t}\n\t\tnewAtom.cleanup = () => {\n\t\t\tfor (const cleanup of cleanupFunctions) {\n\t\t\t\tcleanup()\n\t\t\t}\n\t\t}\n\t}\n\tstore.on.atomCreation.next(token)\n\treturn token\n}\n","import { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const isAtomDefault = (key: string, store: Store): boolean => {\n\tconst core = newest(store)\n\treturn core.atomsThatAreDefault.has(key)\n}\n\nexport const markAtomAsDefault = (key: string, store: Store): void => {\n\tconst core = newest(store)\n\tcore.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key)\n}\n\nexport const markAtomAsNotDefault = (key: string, store: Store): void => {\n\tconst core = newest(store)\n\tcore.atomsThatAreDefault = new Set(newest(store).atomsThatAreDefault)\n\tcore.atomsThatAreDefault.delete(key)\n}\n","import type {\n\tAtomToken,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport { createMutableAtom } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { createRegularAtom } from \"./create-regular-atom\"\n\nexport function createStandaloneAtom<T>(\n\toptions: RegularAtomOptions<T>,\n\tstore: Store,\n): RegularAtomToken<T>\nexport function createStandaloneAtom<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(options: MutableAtomOptions<T, J>, store: Store): MutableAtomToken<T, J>\nexport function createStandaloneAtom<T>(\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n\tstore: Store,\n): AtomToken<T> {\n\tconst isMutable = `mutable` in options\n\n\tif (isMutable) {\n\t\treturn createMutableAtom(options, undefined, store)\n\t}\n\treturn createRegularAtom(options, undefined, store)\n}\n","import type { RegularAtomToken } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { deleteSelector, newest } from \"..\"\n\nexport function deleteAtom(\n\tatomToken: RegularAtomToken<unknown>,\n\tstore: Store,\n): void {\n\tconst target = newest(store)\n\tconst { key } = atomToken\n\tconst atom = target.atoms.get(key)\n\tif (!atom) {\n\t\tstore.logger.error(\n\t\t\t`โŒ`,\n\t\t\t`atom`,\n\t\t\t`${key}`,\n\t\t\t`Tried to delete atom, but it does not exist in the store.`,\n\t\t)\n\t}\n\tatom?.cleanup?.()\n\ttarget.atoms.delete(key)\n\ttarget.valueMap.delete(key)\n\tconst selectorKeys = target.selectorAtoms.getRelatedKeys(key)\n\tif (selectorKeys) {\n\t\tfor (const selectorKey of selectorKeys) {\n\t\t\tconst token =\n\t\t\t\ttarget.selectors.get(selectorKey) ??\n\t\t\t\ttarget.readonlySelectors.get(selectorKey)\n\t\t\tif (token) {\n\t\t\t\tdeleteSelector(token, store)\n\t\t\t}\n\t\t}\n\t}\n\ttarget.selectorAtoms.delete(key)\n\ttarget.atomsThatAreDefault.delete(key)\n\ttarget.timelineAtoms.delete(key)\n\tstore.logger.info(`๐Ÿ”ฅ`, `atom`, `${key}`, `deleted`)\n}\n","import type { Store } from \"./store\"\n\nexport type EnvironmentData = {\n\truntime: `browser` | `node` | `unknown`\n\tstore: Store\n}\n\nexport function getEnvironmentData(store: Store): EnvironmentData {\n\treturn {\n\t\truntime:\n\t\t\ttypeof window === `undefined`\n\t\t\t\t? typeof global === `object`\n\t\t\t\t\t? `node`\n\t\t\t\t\t: `unknown`\n\t\t\t\t: `browser`,\n\t\tstore,\n\t}\n}\n","import type { KeyedStateUpdate } from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport type { Store } from \"../store\"\n\nexport function ingestAtomUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tatomUpdate: KeyedStateUpdate<any>,\n\tstore: Store,\n): void {\n\tconst { key, newValue, oldValue } = atomUpdate\n\tconst value = applying === `newValue` ? newValue : oldValue\n\tsetState({ key, type: `atom` }, value, store)\n}\n","import type { Store } from \"../store\"\nimport type { TimelineSelectorUpdate } from \"../timeline\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\n\nexport function ingestSelectorUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tselectorUpdate: TimelineSelectorUpdate<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? selectorUpdate.atomUpdates\n\t\t\t: [...selectorUpdate.atomUpdates].reverse()\n\tfor (const atomUpdate of updates) {\n\t\tingestAtomUpdate(applying, atomUpdate, store)\n\t}\n}\n","import type { TransactionUpdate } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\n\nexport function ingestTransactionUpdate(\n\tapplying: `newValue` | `oldValue`,\n\ttransactionUpdate: TransactionUpdate<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? transactionUpdate.updates\n\t\t\t: [...transactionUpdate.updates].reverse()\n\tfor (const updateFromTransaction of updates) {\n\t\tif (`newValue` in updateFromTransaction) {\n\t\t\tingestAtomUpdate(applying, updateFromTransaction, store)\n\t\t} else {\n\t\t\tingestTransactionUpdate(applying, updateFromTransaction, store)\n\t\t}\n\t}\n}\n","export class LazyMap<K, V> extends Map<K, V> {\n\tpublic deleted = new Set<K>()\n\n\tpublic constructor(protected readonly source: Map<K, V>) {\n\t\tsuper()\n\t}\n\n\tpublic get(key: K): V | undefined {\n\t\tconst has = super.has(key)\n\t\tif (has) {\n\t\t\treturn super.get(key)\n\t\t}\n\t\tif (!this.deleted.has(key) && this.source.has(key)) {\n\t\t\tconst value = this.source.get(key)\n\t\t\treturn value\n\t\t}\n\t\treturn undefined\n\t}\n\n\tpublic set(key: K, value: V): this {\n\t\tthis.deleted.delete(key)\n\t\treturn super.set(key, value)\n\t}\n\n\tpublic hasOwn(key: K): boolean {\n\t\treturn super.has(key)\n\t}\n\n\tpublic has(key: K): boolean {\n\t\treturn !this.deleted.has(key) && (super.has(key) || this.source.has(key))\n\t}\n\n\tpublic delete(key: K): boolean {\n\t\tthis.deleted.add(key)\n\t\treturn super.delete(key)\n\t}\n}\n","import type { ReadableToken } from \"atom.io\"\n\nimport type { Store } from \"./store\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nfunction prettyPrintTokenType(token: ReadableToken<any>) {\n\tif (token.type === `readonly_selector`) {\n\t\treturn `Readonly Selector`\n\t}\n\treturn capitalize(token.type)\n}\n\nexport class NotFoundError extends Error {\n\tpublic constructor(token: ReadableToken<any>, store: Store) {\n\t\tsuper(\n\t\t\t`${prettyPrintTokenType(token)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import type { AtomToken, TransactionUpdate, ฦ’n } from \"atom.io\"\nimport type { TimelineUpdate } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { getUpdateToken } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineTransactionUpdate,\n} from \"./create-timeline\"\n\nexport const addAtomToTimeline = (\n\tatomToken: AtomToken<any>,\n\ttl: Timeline<any>,\n\tstore: Store,\n): void => {\n\tlet maybeAtom = withdraw(atomToken, store)\n\tif (maybeAtom?.type === `mutable_atom`) {\n\t\tconst updateToken = getUpdateToken(maybeAtom)\n\t\tmaybeAtom = withdraw(updateToken, store)\n\t}\n\tconst atom = maybeAtom\n\tif (atom === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to atom \"${atomToken.key}\" because it has not been initialized in store \"${store.config.name}\"`,\n\t\t)\n\t}\n\tstore.timelineAtoms.set({ atomKey: atom.key, timelineKey: tl.key })\n\n\tatom.subject.subscribe(`timeline`, (update) => {\n\t\t// debugger\n\t\tconst target = newest(store)\n\t\tconst currentSelectorKey =\n\t\t\tstore.operation.open && store.operation.token.type === `selector`\n\t\t\t\t? store.operation.token.key\n\t\t\t\t: null\n\t\tconst currentSelectorTime =\n\t\t\tstore.operation.open && store.operation.token.type === `selector`\n\t\t\t\t? store.operation.time\n\t\t\t\t: null\n\t\tconst currentTransactionKey = target.on.transactionApplying.state?.update.key\n\t\tconst currentTransactionTime = target.on.transactionApplying.state?.time\n\n\t\tstore.logger.info(\n\t\t\t`โณ`,\n\t\t\t`timeline`,\n\t\t\ttl.key,\n\t\t\t`atom`,\n\t\t\tatomToken.key,\n\t\t\t`went`,\n\t\t\tupdate.oldValue,\n\t\t\t`->`,\n\t\t\tupdate.newValue,\n\t\t\tcurrentTransactionKey\n\t\t\t\t? `in transaction \"${currentTransactionKey}\"`\n\t\t\t\t: currentSelectorKey\n\t\t\t\t ? `in selector \"${currentSelectorKey}\"`\n\t\t\t\t : ``,\n\t\t)\n\t\tif (tl.timeTraveling === null) {\n\t\t\tif (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {\n\t\t\t\tconst mostRecentUpdate: TimelineUpdate<any> | undefined =\n\t\t\t\t\ttl.history.at(-1)\n\t\t\t\tif (mostRecentUpdate === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Timeline \"${tl.key}\" has a selectorTime, but no history. This is most likely a bug in AtomIO.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (currentTransactionKey) {\n\t\t\t\tconst currentTransaction = withdraw(\n\t\t\t\t\t{ key: currentTransactionKey, type: `transaction` },\n\t\t\t\t\tstore,\n\t\t\t\t)\n\t\t\t\tif (currentTransaction === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Transaction \"${currentTransactionKey}\" not found in store \"${store.config.name}\". This is surprising, because we are in the application phase of \"${currentTransactionKey}\".`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (tl.transactionKey !== currentTransactionKey) {\n\t\t\t\t\tif (tl.transactionKey) {\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\ttl.key,\n\t\t\t\t\t\t\t`unable to resolve transaction \"${tl.transactionKey}. This is probably a bug in AtomIO.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\ttl.transactionKey = currentTransactionKey\n\t\t\t\t\tconst unsubscribe = currentTransaction.subject.subscribe(\n\t\t\t\t\t\t`timeline:${tl.key}`,\n\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\tif (tl.timeTraveling === null && currentTransactionTime) {\n\t\t\t\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst filterUpdates = (\n\t\t\t\t\t\t\t\t\tupdates: TransactionUpdate<ฦ’n>[`updates`],\n\t\t\t\t\t\t\t\t) =>\n\t\t\t\t\t\t\t\t\tupdates\n\t\t\t\t\t\t\t\t\t\t.filter((updateFromTx) => {\n\t\t\t\t\t\t\t\t\t\t\tconst target = newest(store)\n\t\t\t\t\t\t\t\t\t\t\tif (`updates` in updateFromTx) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn true\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tconst atomOrFamilyKeys =\n\t\t\t\t\t\t\t\t\t\t\t\ttarget.timelineAtoms.getRelatedKeys(tl.key)\n\n\t\t\t\t\t\t\t\t\t\t\treturn atomOrFamilyKeys\n\t\t\t\t\t\t\t\t\t\t\t\t? [...atomOrFamilyKeys].some(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey === updateFromTx.key ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey === updateFromTx.family?.key,\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: false\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t.map((updateFromTx) => {\n\t\t\t\t\t\t\t\t\t\t\tif (`updates` in updateFromTx) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\t...updateFromTx,\n\t\t\t\t\t\t\t\t\t\t\t\t\tupdates: filterUpdates(updateFromTx.updates),\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn updateFromTx\n\t\t\t\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\t\tconst updates = filterUpdates(update.updates)\n\n\t\t\t\t\t\t\t\tconst timelineTransactionUpdate: TimelineTransactionUpdate = {\n\t\t\t\t\t\t\t\t\ttype: `transaction_update`,\n\t\t\t\t\t\t\t\t\ttimestamp: currentTransactionTime,\n\t\t\t\t\t\t\t\t\t...update,\n\t\t\t\t\t\t\t\t\tupdates,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst willCapture =\n\t\t\t\t\t\t\t\t\ttl.shouldCapture?.(timelineTransactionUpdate, tl) ?? true\n\t\t\t\t\t\t\t\tif (willCapture) {\n\t\t\t\t\t\t\t\t\ttl.history.push(timelineTransactionUpdate)\n\t\t\t\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\t\t\t\ttl.subject.next(timelineTransactionUpdate)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttl.transactionKey = null\n\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t`โŒ›`,\n\t\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t\t`got a transaction_update \"${update.key}\"`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (currentSelectorKey && currentSelectorTime) {\n\t\t\t\tlet latestUpdate: TimelineUpdate<any> | undefined = tl.history.at(-1)\n\n\t\t\t\tif (currentSelectorTime !== tl.selectorTime) {\n\t\t\t\t\tlatestUpdate = {\n\t\t\t\t\t\ttype: `selector_update`,\n\t\t\t\t\t\ttimestamp: currentSelectorTime,\n\t\t\t\t\t\tkey: currentSelectorKey,\n\t\t\t\t\t\tatomUpdates: [],\n\t\t\t\t\t}\n\t\t\t\t\tlatestUpdate.atomUpdates.push({\n\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t...update,\n\t\t\t\t\t})\n\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t}\n\n\t\t\t\t\ttl.history.push(latestUpdate)\n\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`โŒ›`,\n\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t`got a selector_update \"${currentSelectorKey}\" with`,\n\t\t\t\t\t\tlatestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),\n\t\t\t\t\t)\n\n\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\ttl.selectorTime = currentSelectorTime\n\t\t\t\t} else {\n\t\t\t\t\tif (latestUpdate?.type === `selector_update`) {\n\t\t\t\t\t\tlatestUpdate.atomUpdates.push({\n\t\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\t...update,\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`set selector_update \"${currentSelectorKey}\" to`,\n\t\t\t\t\t\t\tlatestUpdate?.atomUpdates.map((atomUpdate) => atomUpdate.key),\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (latestUpdate) {\n\t\t\t\t\tconst willCaptureSelectorUpdate =\n\t\t\t\t\t\ttl.shouldCapture?.(latestUpdate, tl) ?? true\n\t\t\t\t\tif (willCaptureSelectorUpdate) {\n\t\t\t\t\t\ttl.subject.next(latestUpdate)\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttl.history.pop()\n\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst timestamp = Date.now()\n\t\t\t\ttl.selectorTime = null\n\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t}\n\t\t\t\tconst atomUpdate: TimelineAtomUpdate<any> = {\n\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\ttimestamp,\n\t\t\t\t\tkey: atom.key,\n\t\t\t\t\toldValue: update.oldValue,\n\t\t\t\t\tnewValue: update.newValue,\n\t\t\t\t}\n\t\t\t\tif (atom.family) {\n\t\t\t\t\tatomUpdate.family = atom.family\n\t\t\t\t}\n\t\t\t\tconst willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true\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`got an atom_update to \"${atom.key}\"`,\n\t\t\t\t)\n\t\t\t\tif (willCapture) {\n\t\t\t\t\ttl.history.push(atomUpdate)\n\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\ttl.subject.next(atomUpdate)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t})\n}\n","import type {\n\tAtomFamily,\n\tFamilyMetadata,\n\tStateUpdate,\n\tTimelineManageable,\n\tTimelineOptions,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTokenType,\n\tTransactionUpdate,\n\tฦ’n,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { getUpdateToken, isMutable } from \"../mutable\"\nimport { type Store, withdraw } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { addAtomToTimeline } from \"./add-atom-to-timeline\"\n\nexport type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> =\n\tStateUpdate<TokenType<ManagedAtom>> & {\n\t\tkey: string\n\t\ttype: `atom_update`\n\t\ttimestamp: number\n\t\tfamily?: FamilyMetadata\n\t}\nexport type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\ttype: `selector_update`\n\ttimestamp: number\n\tatomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[]\n}\nexport type TimelineTransactionUpdate = TransactionUpdate<ฦ’n> & {\n\tkey: string\n\ttype: `transaction_update`\n\ttimestamp: number\n}\n\nexport type Timeline<ManagedAtom extends TimelineManageable> = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<TimelineManageable>,\n\t\ttimeline: Timeline<ManagedAtom>,\n\t) => boolean\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineUpdate<ManagedAtom>[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: Store) => void\n\tsubject: Subject<\n\t\t| TimelineAtomUpdate<ManagedAtom>\n\t\t| TimelineSelectorUpdate<ManagedAtom>\n\t\t| TimelineTransactionUpdate\n\t\t| `redo`\n\t\t| `undo`\n\t>\n}\n\nexport function createTimeline<ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n\tstore: Store,\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: (store) => createTimeline(options, store, tl),\n\t\tsubject: new Subject(),\n\t}\n\tif (options.shouldCapture) {\n\t\ttl.shouldCapture = options.shouldCapture\n\t}\n\tconst timelineKey = options.key\n\tconst target = newest(store)\n\tfor (const tokenOrFamily of options.atoms) {\n\t\tlet atomKey = tokenOrFamily.key\n\t\tif (\n\t\t\ttokenOrFamily.type === `atom_family` ||\n\t\t\ttokenOrFamily.type === `mutable_atom_family`\n\t\t) {\n\t\t\tconst family: AtomFamily<any> = tokenOrFamily\n\t\t\tconst familyKey = family.key\n\t\t\ttarget.timelineAtoms.set({ atomKey: familyKey, timelineKey })\n\t\t\tfamily.subject.subscribe(`timeline:${options.key}`, (token) => {\n\t\t\t\taddAtomToTimeline(token, tl, store)\n\t\t\t})\n\t\t\tfor (const atom of target.atoms.values()) {\n\t\t\t\tif (atom.family?.key === familyKey) {\n\t\t\t\t\taddAtomToTimeline(atom, tl, store)\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tlet atom = withdraw(tokenOrFamily, store)\n\t\t\tif (atom === undefined) {\n\t\t\t\tstore.logger.error(\n\t\t\t\t\t`โŒ`,\n\t\t\t\t\t`timeline`,\n\t\t\t\t\toptions.key,\n\t\t\t\t\t`Failed to add atom \"${atomKey}\" because it does not exist in the store`,\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (isMutable(atom)) {\n\t\t\t\tconst updateAtom = withdraw(getUpdateToken(atom), store)\n\t\t\t\tif (updateAtom === undefined) {\n\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t`โŒ`,\n\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t`Failed to add update atom \"${atomKey}\" because it does not exist in the store`,\n\t\t\t\t\t)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tatom = updateAtom\n\t\t\t\tatomKey = atom.key\n\t\t\t}\n\t\t\tif (`family` in atom) {\n\t\t\t\tconst familyTimelineKey = target.timelineAtoms.getRelatedKey(\n\t\t\t\t\tatom.family.key,\n\t\t\t\t)\n\t\t\t\tif (familyTimelineKey) {\n\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t`โŒ`,\n\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t`Failed to add atom \"${atom.key}\" because its family \"${atom.family.key}\" already belongs to timeline \"${familyTimelineKey}\"`,\n\t\t\t\t\t)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst existingTimelineKey = target.timelineAtoms.getRelatedKey(atomKey)\n\t\t\tif (existingTimelineKey) {\n\t\t\t\tstore.logger.error(\n\t\t\t\t\t`โŒ`,\n\t\t\t\t\t`timeline`,\n\t\t\t\t\toptions.key,\n\t\t\t\t\t`Failed to add atom \"${atomKey}\" because it already belongs to timeline \"${existingTimelineKey}\"`,\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\taddAtomToTimeline(atom, tl, store)\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","import type { TimelineToken } from \"atom.io\"\n\nimport {\n\tingestAtomUpdate,\n\tingestSelectorUpdate,\n\tingestTransactionUpdate,\n} from \"../ingest-updates\"\nimport type { Store } from \"../store\"\n\nexport const timeTravel = (\n\taction: `redo` | `undo`,\n\ttoken: TimelineToken<any>,\n\tstore: Store,\n): void => {\n\tstore.logger.info(\n\t\taction === `redo` ? `โฉ` : `โช`,\n\t\t`timeline`,\n\t\ttoken.key,\n\t\taction,\n\t)\n\tconst timelineData = store.timelines.get(token.key)\n\tif (!timelineData) {\n\t\tstore.logger.error(\n\t\t\t`๐Ÿž`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Failed to ${action}. This timeline has not been initialized.`,\n\t\t)\n\t\treturn\n\t}\n\tif (\n\t\t(action === `redo` && timelineData.at === timelineData.history.length) ||\n\t\t(action === `undo` && timelineData.at === 0)\n\t) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿ’`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Failed to ${action} at the ${\n\t\t\t\taction === `redo` ? `end` : `beginning`\n\t\t\t} of timeline \"${token.key}\". There is nothing to ${action}.`,\n\t\t)\n\t\treturn\n\t}\n\n\ttimelineData.timeTraveling = action === `redo` ? `into_future` : `into_past`\n\tif (action === `undo`) {\n\t\t--timelineData.at\n\t}\n\n\tconst update = timelineData.history[timelineData.at]\n\tconst applying = action === `redo` ? `newValue` : `oldValue`\n\n\tswitch (update.type) {\n\t\tcase `atom_update`: {\n\t\t\tingestAtomUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `selector_update`: {\n\t\t\tingestSelectorUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `transaction_update`: {\n\t\t\tingestTransactionUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif (action === `redo`) {\n\t\t++timelineData.at\n\t}\n\n\ttimelineData.subject.next(action)\n\ttimelineData.timeTraveling = null\n\tstore.logger.info(\n\t\t`โน๏ธ`,\n\t\t`timeline`,\n\t\ttoken.key,\n\t\t`\"${token.key}\" is now at ${timelineData.at} / ${timelineData.history.length}`,\n\t)\n}\n","import { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const abortTransaction = (store: Store): void => {\n\tconst target = newest(store)\n\tif (target.transactionMeta === null || target.parent === null) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿž`,\n\t\t\t`transaction`,\n\t\t\t`???`,\n\t\t\t`abortTransaction called outside of a transaction. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.logger.info(\n\t\t`๐Ÿช‚`,\n\t\t`transaction`,\n\t\ttarget.transactionMeta.update.key,\n\t\t`Aborting transaction`,\n\t)\n\ttarget.parent.child = null\n}\n","import type { ฦ’n } from \"atom.io\"\n\nimport { ingestTransactionUpdate } from \"../ingest-updates\"\nimport { newest } from \"../lineage\"\nimport { withdraw } from \"../store\"\nimport type { Store } from \"../store\"\n\nexport const applyTransaction = <ฦ’ extends ฦ’n>(\n\toutput: ReturnType<ฦ’>,\n\tstore: Store,\n): void => {\n\tconst child = newest(store)\n\tconst { parent } = child\n\tif (\n\t\tparent === null ||\n\t\tchild.transactionMeta === null ||\n\t\tchild.transactionMeta?.phase !== `building`\n\t) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿž`,\n\t\t\t`transaction`,\n\t\t\t`???`,\n\t\t\t`applyTransaction called outside of a transaction. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tchild.transactionMeta.phase = `applying`\n\tchild.transactionMeta.update.output = output\n\tparent.child = null\n\tparent.on.transactionApplying.next(child.transactionMeta)\n\tconst { updates } = child.transactionMeta.update\n\tstore.logger.info(\n\t\t`๐Ÿ›„`,\n\t\t`transaction`,\n\t\tchild.transactionMeta.update.key,\n\t\t`Applying transaction with ${updates.length} updates:`,\n\t\tupdates,\n\t)\n\tfor (const tracker of child.trackers.values()) {\n\t\tconst mutableKey = tracker.mutableState.key\n\t\tif (!parent.atoms.has(mutableKey)) {\n\t\t\tconst atom = child.atoms.get(mutableKey)\n\t\t\tatom?.install(parent)\n\t\t}\n\t\ttracker.dispose()\n\t}\n\tfor (const atom of child.atoms.values()) {\n\t\tif (!parent.atoms.has(atom.key)) {\n\t\t\tparent.atoms.set(atom.key, atom)\n\t\t\tparent.valueMap.set(atom.key, atom.default)\n\t\t\tparent.logger.info(\n\t\t\t\t`๐Ÿ”จ`,\n\t\t\t\t`transaction`,\n\t\t\t\tchild.transactionMeta.update.key,\n\t\t\t\t`Adding atom \"${atom.key}\"`,\n\t\t\t)\n\t\t}\n\t}\n\tingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent)\n\tif (parent.transactionMeta === null) {\n\t\tconst myTransaction = withdraw<ฦ’>(\n\t\t\t{ key: child.transactionMeta.update.key, type: `transaction` },\n\t\t\tstore,\n\t\t)\n\t\tmyTransaction?.subject.next(child.transactionMeta.update)\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ›ฌ`,\n\t\t\t`transaction`,\n\t\t\tchild.transactionMeta.update.key,\n\t\t\t`Finished applying transaction.`,\n\t\t)\n\t} else {\n\t\tparent.transactionMeta.update.updates.push(child.transactionMeta.update)\n\t}\n\tparent.on.transactionApplying.next(null)\n}\n","import { findInStore, getState, runTransaction, setState } from \"atom.io\"\nimport type { findState } from \"atom.io\"\n\nimport { Junction } from \"~/packages/rel8/junction/src\"\n\nimport { getEnvironmentData } from \"../get-environment-data\"\nimport { LazyMap } from \"../lazy-map\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const buildTransaction = (\n\tkey: string,\n\tparams: any[],\n\tstore: Store,\n\tid?: string,\n): void => {\n\tconst parent = newest(store)\n\tconst child: Store = {\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\ttransactionMeta: null,\n\t\tatoms: new LazyMap(parent.atoms),\n\t\tatomsThatAreDefault: new Set(parent.atomsThatAreDefault),\n\t\tfamilies: new LazyMap(parent.families),\n\t\toperation: { open: false },\n\t\treadonlySelectors: new LazyMap(parent.readonlySelectors),\n\t\ttimelines: new LazyMap(parent.timelines),\n\t\ttimelineAtoms: new Junction(parent.timelineAtoms.toJSON()),\n\t\ttrackers: new Map(),\n\t\ttransactions: new LazyMap(parent.transactions),\n\t\tselectorAtoms: new Junction(parent.selectorAtoms.toJSON()),\n\t\tselectorGraph: new Junction(parent.selectorGraph.toJSON(), {\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t}),\n\t\tselectors: new LazyMap(parent.selectors),\n\t\tvalueMap: new LazyMap(parent.valueMap),\n\t}\n\tchild.transactionMeta = {\n\t\tphase: `building`,\n\t\ttime: Date.now(),\n\t\tupdate: {\n\t\t\tkey,\n\t\t\tid: id ?? Math.random().toString(36).slice(2),\n\t\t\tupdates: [],\n\t\t\tparams,\n\t\t\toutput: undefined,\n\t\t},\n\t\ttransactors: {\n\t\t\tget: (token) => getState(token, child),\n\t\t\tset: (token, value) => setState(token, value, child),\n\t\t\trun: (token) => runTransaction(token, child),\n\t\t\tfind: ((token, key) => findInStore(token, key, child)) as typeof findState,\n\t\t\tenv: () => getEnvironmentData(child),\n\t\t},\n\t}\n\tparent.child = child\n\tstore.logger.info(\n\t\t`๐Ÿ›ซ`,\n\t\t`transaction`,\n\t\tkey,\n\t\t`Building transaction with params:`,\n\t\tparams,\n\t)\n}\n","import type {\n\tTransactionOptions,\n\tTransactionToken,\n\tTransactionUpdate,\n\tฦ’n,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { deposit } from \"../store\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { abortTransaction } from \"./abort-transaction\"\nimport { applyTransaction } from \"./apply-transaction\"\nimport { buildTransaction } from \"./build-transaction\"\n\nexport type Transaction<ฦ’ extends ฦ’n> = {\n\tkey: string\n\ttype: `transaction`\n\tinstall: (store: Store) => void\n\tsubject: Subject<TransactionUpdate<ฦ’>>\n\trun: (parameters: Parameters<ฦ’>, id?: string) => ReturnType<ฦ’>\n}\n\nexport function createTransaction<ฦ’ extends ฦ’n>(\n\toptions: TransactionOptions<ฦ’>,\n\tstore: Store,\n): TransactionToken<ฦ’> {\n\tconst newTransaction: Transaction<ฦ’> = {\n\t\tkey: options.key,\n\t\ttype: `transaction`,\n\t\trun: (params: Parameters<ฦ’>, id?: string) => {\n\t\t\tbuildTransaction(options.key, params, store, id)\n\t\t\ttry {\n\t\t\t\tconst target = newest(store)\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: this happens right above\n\t\t\t\tconst { transactors } = target.transactionMeta!\n\t\t\t\tconst output = options.do(transactors, ...params)\n\t\t\t\tapplyTransaction(output, target)\n\t\t\t\treturn output\n\t\t\t} catch (thrown) {\n\t\t\t\tabortTransaction(target)\n\t\t\t\tstore.logger.warn(`๐Ÿ’ฅ`, `transaction`, options.key, `caught:`, thrown)\n\t\t\t\tthrow thrown\n\t\t\t}\n\t\t},\n\t\tinstall: (store) => createTransaction(options, store),\n\t\tsubject: new Subject(),\n\t}\n\tconst target = newest(store)\n\ttarget.transactions.set(newTransaction.key, newTransaction)\n\tconst token = deposit(newTransaction)\n\tstore.on.transactionCreation.next(token)\n\treturn token\n}\n","import type { TransactionUpdate, TransactorsWithRunAndEnv, ฦ’n } from \"atom.io\"\n\nexport * from \"./abort-transaction\"\nexport * from \"./apply-transaction\"\nexport * from \"./build-transaction\"\nexport * from \"./create-transaction\"\n\nexport const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const\nexport type TransactionPhase = (typeof TRANSACTION_PHASES)[number]\n\nexport type TransactionMeta<ฦ’ extends ฦ’n> = {\n\tphase: `applying` | `building`\n\ttime: number\n\tupdate: TransactionUpdate<ฦ’>\n\ttransactors: TransactorsWithRunAndEnv\n}\n"]}
1
+ {"version":3,"sources":["../src/mutable/create-mutable-atom.ts","../src/lineage.ts","../src/store/deposit.ts","../src/store/store.ts","../../../rel8/junction/src/junction.ts","../src/subject.ts","../src/store/withdraw.ts","../src/store/withdraw-new-family-member.ts","../src/future.ts","../src/set-state/copy-mutable-if-needed.ts","../src/set-state/copy-mutable-in-transaction.ts","../src/caching.ts","../src/read-or-compute-value.ts","../src/selector/register-selector.ts","../src/set-state/become.ts","../src/operation.ts","../src/set-state/emit-update.ts","../src/set-state/evict-downstream.ts","../src/set-state/stow-update.ts","../src/set-state/set-atom.ts","../src/set-state/set-atom-or-selector.ts","../src/keys.ts","../src/selector/get-selector-dependency-keys.ts","../src/selector/trace-selector-atoms.ts","../src/selector/update-selector-atoms.ts","../src/selector/create-readonly-selector.ts","../src/selector/create-writable-selector.ts","../src/selector/create-standalone-selector.ts","../src/selector/delete-selector.ts","../src/subscribe/recall-state.ts","../src/subscribe/subscribe-to-root-atoms.ts","../src/subscribe/subscribe-to-state.ts","../src/subscribe/subscribe-to-timeline.ts","../src/subscribe/subscribe-to-transaction.ts","../src/mutable/tracker.ts","../src/mutable/create-mutable-atom-family.ts","../src/mutable/tracker-family.ts","../src/families/create-regular-atom-family.ts","../src/families/create-atom-family.ts","../src/families/create-readonly-selector-family.ts","../src/families/create-writable-selector-family.ts","../src/families/create-selector-family.ts","../src/mutable/get-json-family.ts","../src/mutable/get-json-token.ts","../src/mutable/get-update-token.ts","../src/mutable/is-mutable.ts","../src/mutable/transceiver.ts","../src/atom/create-regular-atom.ts","../src/atom/is-default.ts","../src/atom/create-standalone-atom.ts","../src/atom/delete-atom.ts","../src/get-environment-data.ts","../src/ingest-updates/ingest-atom-update.ts","../src/ingest-updates/ingest-selector-update.ts","../src/ingest-updates/ingest-transaction-update.ts","../src/lazy-map.ts","../src/not-found-error.ts","../src/timeline/add-atom-to-timeline.ts","../src/timeline/create-timeline.ts","../src/timeline/time-travel.ts","../src/transaction/abort-transaction.ts","../src/transaction/apply-transaction.ts","../src/transaction/build-transaction.ts","../src/transaction/create-transaction.ts","../src/transaction/index.ts"],"names":["setState","a","b","withdraw","target","update","unsubscribe","store","stringifyJson","isMutable","_a","_b","updates","token","findInStore","getState","key"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAMA,SAAS,YAAAA,iBAAgB;AAEzB,SAAS,kBAAkB;;;ACHpB,SAAS,OAA0B,OAAa;AACtD,SAAO,MAAM,UAAU,MAAM;AAC5B,YAAQ,MAAM;AAAA,EACf;AACA,SAAO;AACR;;;ACwBO,SAAS,QACf,OAUsB;AACtB,QAAM,QAAQ;AAAA,IACb,KAAK,MAAM;AAAA,IACX,MAAM,MAAM;AAAA,EACb;AACA,MAAI,YAAY,OAAO;AACtB,UAAM,SAAS,MAAM;AAAA,EACtB;AACA,SAAO;AACR;;;ACtDA,SAAS,oBAAoB;;;ACoDtB,IAAM,WAAN,MAIL;AAAA,EA0FM,YACN,MACA,QACC;AAzFF,SAAgB,YAAY,oBAAI,IAAyB;AACzD,SAAgB,WAAW,oBAAI,IAAqB;AAGpD,SAAO,iBAAiB,CAAC,GAAW,MAAsB,GAAG,CAAC,IAAI,CAAC;AAhEpE;AAsJE,SAAK,IAAI,KAAK,QAAQ,CAAC;AACvB,SAAK,IAAI,KAAK,QAAQ,CAAC;AAEvB,SAAK,cAAc,KAAK;AACxB,QAAI,EAAC,iCAAQ,gBAAe;AAC3B,WAAK,YAAY,IAAI,KAAI,UAAK,cAAL,mBAAgB,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,EAAE;AACzE,WAAK,WAAW,IAAI,IAAI,KAAK,QAAQ;AAAA,IACtC;AACA,SAAK,aAAY,sCAAQ,cAAR,YAAqB;AACtC,QAAI,iCAAQ,gBAAgB;AAC3B,WAAK,iBAAiB,OAAO;AAAA,IAC9B;AACA,QAAI,iCAAQ,eAAe;AAC1B,YAAM,gBAAgB,OA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B,OAAgB;AAC5C,uBAAiB,QAAQ,KAAK,QAAQ,OAAO,EAAE;AAC/C,UAAI;AACH,cAAMZ,UAAS,OAAO,KAAK;AAE3B,cAAM,EAAE,YAAY,IAAIA,QAAO;AAC/B,cAAM,SAAS,QAAQ,GAAG,aAAa,GAAG,MAAM;AAChD,yBAAiB,QAAQA,OAAM;AAC/B,eAAO;AAAA,MACR,SAAS,QAAQ;AAChB,yBAAiB,MAAM;AACvB,cAAM,OAAO,KAAK,aAAM,eAAe,QAAQ,KAAK,WAAW,MAAM;AACrE,cAAM;AAAA,MACP;AAAA,IACD;AAAA,IACA,SAAS,CAACG,WAAU,kBAAkB,SAASA,MAAK;AAAA,IACpD,SAAS,IAAI,QAAQ;AAAA,EACtB;AACA,QAAM,SAAS,OAAO,KAAK;AAC3B,SAAO,aAAa,IAAI,eAAe,KAAK,cAAc;AAC1D,QAAM,QAAQ,QAAQ,cAAc;AACpC,QAAM,GAAG,oBAAoB,KAAK,KAAK;AACvC,SAAO;AACR;;;AC9CO,IAAM,qBAAqB,CAAC,QAAQ,YAAY,UAAU","sourcesContent":["import type { UpdateHandler } from \"atom.io\"\nimport type {\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n} from \"atom.io\"\nimport { setState } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJson } from \"atom.io/json\"\n\nimport { type MutableAtom, cacheValue } from \"..\"\nimport { createRegularAtom, markAtomAsDefault } from \"../atom\"\nimport { newest } from \"../lineage\"\nimport { type Store, deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtom<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(\n\toptions: MutableAtomOptions<T, J>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): MutableAtomToken<T, J> {\n\tstore.logger.info(\n\t\t`๐Ÿ”จ`,\n\t\t`atom`,\n\t\toptions.key,\n\t\t`creating in store \"${store.config.name}\"`,\n\t)\n\tconst target = newest(store)\n\tconst existing = target.atoms.get(options.key)\n\tif (existing && existing.type === `mutable_atom`) {\n\t\tstore.logger.error(\n\t\t\t`โŒ`,\n\t\t\t`atom`,\n\t\t\toptions.key,\n\t\t\t`Tried to create atom, but it already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: MutableAtom<T, J> = {\n\t\t...options,\n\t\ttype: `mutable_atom`,\n\t\tinstall: (store: Store) => {\n\t\t\tstore.logger.info(\n\t\t\t\t`๐Ÿ› ๏ธ`,\n\t\t\t\t`atom`,\n\t\t\t\toptions.key,\n\t\t\t\t`installing in store \"${store.config.name}\"`,\n\t\t\t)\n\t\t\treturn createMutableAtom(options, family, store)\n\t\t},\n\t\tsubject,\n\t} as const\n\tif (family) {\n\t\tnewAtom.family = family\n\t}\n\tconst initialValue = options.default()\n\ttarget.atoms.set(newAtom.key, newAtom)\n\tmarkAtomAsDefault(options.key, store)\n\tcacheValue(options.key, initialValue, subject, target)\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\tsetSelf: (next) => setState(token, next, store),\n\t\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\t\tsubscribeToState(token, handle, `effect[${effectIndex}]`, store),\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\tselectJson(token, options, store)\n\n\tstore.on.atomCreation.next(token)\n\n\treturn token\n}\n","export interface Lineage {\n\tparent: typeof this | null\n\tchild: typeof this | null\n}\n\nexport function newest<T extends Lineage>(scion: T): T {\n\twhile (scion.child !== null) {\n\t\tscion = scion.child\n\t}\n\treturn scion\n}\n","import type {\n\tMutableAtomToken,\n\tReadableToken,\n\tReadonlySelectorToken,\n\tRegularAtomToken,\n\tSelectorToken,\n\tTransactionToken,\n\tWritableSelectorToken,\n\tWritableToken,\n\tฦ’n,\n} from \"atom.io\"\n\nimport type {\n\tMutableAtom,\n\tReadableState,\n\tReadonlySelector,\n\tRegularAtom,\n\tTransceiver,\n\tWritableSelector,\n\tWritableState,\n} from \"..\"\nimport type { Transaction } from \"../transaction\"\n\nexport function deposit<T>(state: RegularAtom<T>): RegularAtomToken<T>\nexport function deposit<T extends Transceiver<any>>(\n\tstate: MutableAtom<T, any>,\n): MutableAtomToken<T, any>\nexport function deposit<T>(state: WritableSelector<T>): WritableSelectorToken<T>\nexport function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>\nexport function deposit<T>(state: WritableState<T>): WritableToken<T>\nexport function deposit<T>(\n\tstate: Transaction<T extends ฦ’n ? T : never>,\n): TransactionToken<T>\nexport function deposit<T>(state: ReadableState<T>): ReadableToken<T>\nexport function deposit<T>(\n\tstate:\n\t\t| ReadonlySelector<T>\n\t\t| RegularAtom<T>\n\t\t| Transaction<T extends ฦ’n ? T : never>\n\t\t| WritableSelector<T>\n\t\t| (T extends Transceiver<any> ? MutableAtom<T, any> : never),\n):\n\t| MutableAtomToken<T extends Transceiver<any> ? T : never, any>\n\t| RegularAtomToken<T>\n\t| SelectorToken<T>\n\t| TransactionToken<T> {\n\tconst token = {\n\t\tkey: state.key,\n\t\ttype: state.type,\n\t} as any\n\tif (`family` in state) {\n\t\ttoken.family = state.family\n\t}\n\treturn token\n}\n","import { AtomIOLogger } from \"atom.io\"\nimport type {\n\tAtomToken,\n\tLogger,\n\tMutableAtomFamily,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tRegularAtomFamily,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableSelectorFamily,\n\tWritableSelectorToken,\n\tฦ’n,\n} from \"atom.io\"\n\nimport { Junction } from \"~/packages/rel8/junction/src\"\n\nimport type {\n\tAtom,\n\tReadonlySelector,\n\tTracker,\n\tTransceiver,\n\tWritableSelector,\n} from \"..\"\nimport type { Lineage } from \"../lineage\"\nimport { getJsonToken, getUpdateToken } from \"../mutable\"\nimport type { OperationProgress } from \"../operation\"\nimport { StatefulSubject, Subject } from \"../subject\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction, TransactionMeta } from \"../transaction\"\n\nexport class Store implements Lineage {\n\tpublic parent: Store | null = null\n\tpublic child: Store | null = null\n\n\tpublic valueMap = new Map<string, any>()\n\n\tpublic atoms = new Map<string, Atom<any>>()\n\tpublic selectors = new Map<string, WritableSelector<any>>()\n\tpublic readonlySelectors = new Map<string, ReadonlySelector<any>>()\n\n\tpublic trackers = new Map<string, Tracker<Transceiver<any>>>()\n\tpublic families = new Map<\n\t\tstring,\n\t\t| MutableAtomFamily<any, any, any>\n\t\t| ReadonlySelectorFamily<any, any>\n\t\t| RegularAtomFamily<any, any>\n\t\t| WritableSelectorFamily<any, any>\n\t>()\n\n\tpublic timelines = new Map<string, Timeline<any>>()\n\tpublic transactions = new Map<string, Transaction<ฦ’n>>()\n\n\tpublic atomsThatAreDefault = new Set<string>()\n\n\tpublic timelineAtoms = new Junction({\n\t\tbetween: [`timelineKey`, `atomKey`],\n\t\tcardinality: `1:n`,\n\t})\n\tpublic selectorAtoms = new Junction({\n\t\tbetween: [`selectorKey`, `atomKey`],\n\t\tcardinality: `n:n`,\n\t})\n\tpublic selectorGraph = new Junction<\n\t\t`upstreamSelectorKey`,\n\t\t`downstreamSelectorKey`,\n\t\t{ source: string }\n\t>(\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\n\tpublic on = {\n\t\tatomCreation: new Subject<AtomToken<unknown>>(),\n\t\tselectorCreation: new Subject<\n\t\t\tReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>\n\t\t>(),\n\t\ttransactionCreation: new Subject<TransactionToken<ฦ’n>>(),\n\t\ttimelineCreation: new Subject<TimelineToken<unknown>>(),\n\t\ttransactionApplying: new StatefulSubject<TransactionMeta<ฦ’n> | null>(null),\n\t\toperationClose: new Subject<OperationProgress>(),\n\t}\n\tpublic operation: OperationProgress = { open: false }\n\tpublic transactionMeta: TransactionMeta<ฦ’n> | null = null\n\n\tpublic config: {\n\t\tname: string\n\t} = {\n\t\tname: `IMPLICIT_STORE`,\n\t}\n\n\tpublic loggers: AtomIOLogger[] = [\n\t\tnew AtomIOLogger(`warn`, (_, __, key) => !key.includes(`๐Ÿ‘โ€๐Ÿ—จ`)),\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(name: string, store: Store | null = null) {\n\t\tif (store !== null) {\n\t\t\tthis.valueMap = new Map(store?.valueMap)\n\t\t\tthis.operation = { ...store?.operation }\n\t\t\tthis.transactionMeta = null\n\t\t\tthis.config = {\n\t\t\t\t...store?.config,\n\t\t\t\tname,\n\t\t\t}\n\t\t\tfor (const [, family] of store.families) {\n\t\t\t\tfamily.install(this)\n\t\t\t}\n\t\t\tconst mutableHelpers = new Set<string>()\n\t\t\tfor (const [, atom] of store.atoms) {\n\t\t\t\tif (mutableHelpers.has(atom.key)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tatom.install(this)\n\t\t\t\tif (atom.type === `mutable_atom`) {\n\t\t\t\t\tconst originalJsonToken = getJsonToken(atom)\n\t\t\t\t\tconst originalUpdateToken = getUpdateToken(atom)\n\t\t\t\t\tmutableHelpers.add(originalJsonToken.key)\n\t\t\t\t\tmutableHelpers.add(originalUpdateToken.key)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [, selector] of store.readonlySelectors) {\n\t\t\t\tselector.install(this)\n\t\t\t}\n\t\t\tfor (const [, selector] of store.selectors) {\n\t\t\t\tif (mutableHelpers.has(selector.key)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tselector.install(this)\n\t\t\t}\n\t\t\tfor (const [, tx] of store.transactions) {\n\t\t\t\ttx.install(this)\n\t\t\t}\n\t\t\tfor (const [, timeline] of store.timelines) {\n\t\t\t\ttimeline.install(this)\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const IMPLICIT = {\n\tSTORE_INTERNAL: undefined as Store | undefined,\n\tget STORE(): Store {\n\t\treturn (\n\t\t\tthis.STORE_INTERNAL ?? (this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`))\n\t\t)\n\t},\n}\n\nexport const clearStore = (store: Store): void => {\n\tconst { config } = store\n\tObject.assign(store, new Store(config.name))\n\tstore.config = config\n}\n","import type { Cardinality, Json, Refinement } from \"rel8\"\n\nexport interface JunctionEntries<Content extends Json.Object | null>\n\textends Json.Object {\n\treadonly relations: [string, string[]][]\n\treadonly contents: [string, Content][]\n}\nexport interface JunctionSchema<ASide extends string, BSide extends string>\n\textends Json.Object {\n\treadonly between: [a: ASide, b: BSide]\n\treadonly cardinality: Cardinality\n}\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<Content extends Json.Object | null> = {\n\texternalStore?: ExternalStoreConfiguration<Content>\n\tisContent?: Refinement<unknown, Content>\n\tmakeContentKey?: (a: string, b: string) => string\n}\n\nexport type JunctionJSON<\n\tASide extends string,\n\tBSide extends string,\n\tContent extends Json.Object | null,\n> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>\n\nexport class Junction<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Content extends Json.Object | null = null,\n> {\n\tpublic readonly a: ASide\n\tpublic readonly b: BSide\n\tpublic readonly cardinality: Cardinality\n\tpublic readonly relations = new Map<string, Set<string>>()\n\tpublic readonly contents = new Map<string, Content>()\n\n\tpublic isContent: Refinement<unknown, Content> | null\n\tpublic makeContentKey = (a: string, b: string): string => `${a}:${b}`\n\n\tpublic getRelatedKeys(key: string): Set<string> | undefined {\n\t\treturn this.relations.get(key)\n\t}\n\tprotected addRelation(a: string, b: string): void {\n\t\tlet aRelations = this.relations.get(a)\n\t\tlet bRelations = this.relations.get(b)\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: string, b: string): void {\n\t\tconst aRelations = this.relations.get(a)\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)\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: string, bs: string[]): void {\n\t\tthis.relations.set(a, new Set(bs))\n\t\tfor (const b of bs) {\n\t\t\tconst bRelations = new Set([a])\n\t\t\tthis.relations.set(b, bRelations)\n\t\t}\n\t}\n\tprotected replaceRelationsSafely(a: string, bs: string[]): void {\n\t\tconst aRelationsPrev = this.relations.get(a)\n\t\tif (aRelationsPrev) {\n\t\t\tfor (const b of aRelationsPrev) {\n\t\t\t\tconst bRelations = this.relations.get(b)\n\t\t\t\tif (bRelations) {\n\t\t\t\t\tif (bRelations.size === 1) {\n\t\t\t\t\t\tthis.relations.delete(b)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbRelations.delete(a)\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(a, new Set(bs))\n\t\tfor (const b of bs) {\n\t\t\tlet bRelations = this.relations.get(b)\n\t\t\tif (bRelations) {\n\t\t\t\tbRelations.add(a)\n\t\t\t} else {\n\t\t\t\tbRelations = new Set([a])\n\t\t\t\tthis.relations.set(b, bRelations)\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected getContentInternal(contentKey: string): Content | undefined {\n\t\treturn this.contents.get(contentKey)\n\t}\n\tprotected setContent(contentKey: string, content: Content): void {\n\t\tthis.contents.set(contentKey, content)\n\t}\n\tprotected deleteContent(contentKey: string): void {\n\t\tthis.contents.delete(contentKey)\n\t}\n\n\tpublic constructor(\n\t\tdata: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>,\n\t\tconfig?: JunctionAdvancedConfiguration<Content>,\n\t) {\n\t\tthis.a = data.between[0]\n\t\tthis.b = data.between[1]\n\n\t\tthis.cardinality = data.cardinality\n\t\tif (!config?.externalStore) {\n\t\t\tthis.relations = new Map(data.relations?.map(([a, b]) => [a, new Set(b)]))\n\t\t\tthis.contents = new Map(data.contents)\n\t\t}\n\t\tthis.isContent = config?.isContent ?? null\n\t\tif (config?.makeContentKey) {\n\t\t\tthis.makeContentKey = config.makeContentKey\n\t\t}\n\t\tif (config?.externalStore) {\n\t\t\tconst externalStore = config.externalStore\n\t\t\tthis.has = (a, b) => externalStore.has(a, b)\n\t\t\tthis.addRelation = (a, b) => {\n\t\t\t\texternalStore.addRelation(a, b)\n\t\t\t}\n\t\t\tthis.deleteRelation = (a, b) => {\n\t\t\t\texternalStore.deleteRelation(a, b)\n\t\t\t}\n\t\t\tthis.replaceRelationsSafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsSafely(a, bs)\n\t\t\t}\n\t\t\tthis.replaceRelationsUnsafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsUnsafely(a, bs)\n\t\t\t}\n\t\t\tthis.getRelatedKeys = (key) => externalStore.getRelatedKeys(key)\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\tfor (const y of ys) this.addRelation(x, y)\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}\n\tpublic toJSON(): JunctionJSON<ASide, BSide, 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(([a, b]) => [a, [...b]]),\n\t\t\tcontents: [...this.contents.entries()],\n\t\t}\n\t}\n\n\tpublic set(\n\t\ta: string,\n\t\t...rest: Content extends null ? [b: string] : [b: string, content: Content]\n\t): this\n\tpublic set(\n\t\trelation: { [Key in ASide | BSide]: string },\n\t\t...rest: Content extends null ? [] | [b?: undefined] : [content: Content]\n\t): this\n\tpublic set(\n\t\ta: string | { [Key in ASide | BSide]: string },\n\t\t...rest: Content extends null\n\t\t\t? [] | [b?: string | undefined]\n\t\t\t: [b: string, content: Content] | [content: Content]\n\t): this {\n\t\tconst b: string =\n\t\t\ttypeof rest[0] === `string`\n\t\t\t\t? rest[0]\n\t\t\t\t: (a[this.b as keyof typeof a] as string)\n\t\tconst content: Content | undefined =\n\t\t\trest[1] ?? typeof rest[0] === `string` ? undefined : (rest[0] as Content)\n\t\ta = typeof a === `string` ? a : a[this.a]\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(bPrev, a)\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst aPrev = this.getRelatedKey(b)\n\t\t\t\tif (aPrev && aPrev !== a) this.delete(aPrev, b)\n\t\t\t}\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: string, b?: string): this\n\tpublic delete(\n\t\trelation:\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>,\n\t\tb?: undefined,\n\t): this\n\tpublic delete(\n\t\tx:\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>\n\t\t\t| string,\n\t\tb?: string | undefined,\n\t): this {\n\t\t// @ts-expect-error we deduce that this.b may index x\n\t\tb = typeof b === `string` ? b : (x[this.b] as string | undefined)\n\t\t// @ts-expect-error we deduce that this.a may index x\n\t\tconst a = typeof x === `string` ? x : (x[this.a] as string | undefined)\n\n\t\tif (a === undefined && typeof b === `string`) {\n\t\t\tconst bRelations = this.getRelatedKeys(b)\n\t\t\tif (bRelations) {\n\t\t\t\tfor (const a of bRelations) {\n\t\t\t\t\tthis.delete(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && b === undefined) {\n\t\t\tconst aRelations = this.getRelatedKeys(a)\n\t\t\tif (aRelations) {\n\t\t\t\tfor (const b of aRelations) {\n\t\t\t\t\tthis.delete(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && typeof b === `string`) {\n\t\t\tthis.deleteRelation(a, b)\n\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\tthis.deleteContent(contentKey)\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic getRelatedKey(key: string): string | undefined {\n\t\tconst relations = this.getRelatedKeys(key)\n\t\tif (relations) {\n\t\t\tif (relations.size > 1) {\n\t\t\t\tconsole.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\tfor (const relation of relations) {\n\t\t\t\treturn relation\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic replaceRelations(\n\t\ta: string,\n\t\trelations: Content extends null ? string[] : Record<string, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this {\n\t\tconst hasContent = !Array.isArray(relations)\n\t\tconst bs = hasContent ? Object.keys(relations) : relations\n\t\tif (config?.reckless) {\n\t\t\tthis.replaceRelationsUnsafely(a, bs)\n\t\t} else {\n\t\t\tthis.replaceRelationsSafely(a, bs)\n\t\t}\n\t\tif (hasContent) {\n\t\t\tfor (const b of bs) {\n\t\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\t\tconst content = relations[b] as Content\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: string, b: string): Content | undefined {\n\t\tconst contentKey = this.makeContentKey(a, b)\n\t\treturn this.getContentInternal(contentKey)\n\t}\n\n\tpublic getRelationEntries(\n\t\tinput: Record<ASide, string> | Record<BSide, string>,\n\t): [string, Content][] {\n\t\tconst a: string | undefined = (input as any)[this.a]\n\t\tconst b: string | 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((b) => {\n\t\t\t\t\treturn [b, this.getContent(a, b) ?? (null 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((a) => {\n\t\t\t\t\treturn [a, this.getContent(a, b) ?? (null as Content)]\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn []\n\t}\n\n\tpublic has(a: string, b?: string): boolean {\n\t\tif (b) {\n\t\t\tconst setA = this.getRelatedKeys(a)\n\t\t\treturn setA?.has(b) ?? false\n\t\t}\n\t\treturn this.relations.has(a)\n\t}\n}\n","export class Subject<T> {\n\tpublic Subscriber: (value: T) => void\n\n\tpublic subscribers: Map<string, this[`Subscriber`]> = new Map()\n\n\tpublic subscribe(key: string, subscriber: this[`Subscriber`]): () => void {\n\t\tthis.subscribers.set(key, subscriber)\n\t\tconst unsubscribe = () => this.unsubscribe(key)\n\t\treturn unsubscribe\n\t}\n\n\tprivate unsubscribe(key: string) {\n\t\tthis.subscribers.delete(key)\n\t}\n\n\tpublic next(value: T): void {\n\t\tconst subscribers = this.subscribers.values()\n\t\tfor (const subscriber of subscribers) {\n\t\t\tsubscriber(value)\n\t\t}\n\t}\n}\n\nexport class StatefulSubject<T> extends Subject<T> {\n\tpublic state: T\n\n\tpublic constructor(initialState: T) {\n\t\tsuper()\n\t\tthis.state = initialState\n\t}\n\n\tpublic next(value: T): void {\n\t\tthis.state = value\n\t\tsuper.next(value)\n\t}\n}\n","import type {\n\tAtomToken,\n\tMutableAtomToken,\n\tReadableToken,\n\tReadonlySelectorToken,\n\tRegularAtomToken,\n\tSelectorToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableSelectorToken,\n\tWritableToken,\n\tฦ’n,\n} from \"atom.io\"\n\nimport type {\n\tAtom,\n\tMutableAtom,\n\tReadableState,\n\tReadonlySelector,\n\tRegularAtom,\n\tSelector,\n\tTransceiver,\n\tWritableSelector,\n\tWritableState,\n} from \"..\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Store } from \"./store\"\n\nexport type Withdrawable = ReadableState<any> | Timeline<any> | Transaction<any>\n\nexport function withdraw<T>(\n\ttoken: RegularAtomToken<T>,\n\tstore: Store,\n): RegularAtom<T> | undefined\nexport function withdraw<T extends Transceiver<any>>(\n\ttoken: MutableAtomToken<T, any>,\n\tstore: Store,\n): MutableAtom<T, any> | undefined\nexport function withdraw<T>(\n\ttoken: AtomToken<T>,\n\tstore: Store,\n): Atom<T> | undefined\nexport function withdraw<T>(\n\ttoken: WritableSelectorToken<T>,\n\tstore: Store,\n): WritableSelector<T> | undefined\nexport function withdraw<T>(\n\ttoken: ReadonlySelectorToken<T>,\n\tstore: Store,\n): ReadonlySelector<T> | undefined\nexport function withdraw<T>(\n\ttoken: SelectorToken<T>,\n\tstore: Store,\n): Selector<T> | undefined\nexport function withdraw<T>(\n\ttoken: WritableToken<T>,\n\tstore: Store,\n): WritableState<T> | undefined\nexport function withdraw<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Store,\n): ReadableState<T> | undefined\nexport function withdraw<T>(\n\ttoken: TransactionToken<T>,\n\tstore: Store,\n): Transaction<T extends ฦ’n ? T : never> | undefined\nexport function withdraw<T>(\n\ttoken: TimelineToken<T>,\n\tstore: Store,\n): Timeline<T extends TimelineManageable ? T : never> | undefined\nexport function withdraw<T>(\n\ttoken:\n\t\t| RegularAtomToken<T>\n\t\t| SelectorToken<T>\n\t\t| TimelineToken<T>\n\t\t| TransactionToken<T>\n\t\t| (T extends Transceiver<any> ? MutableAtomToken<T, any> : never),\n\tstore: Store,\n): Withdrawable | undefined {\n\tlet withdrawn: Withdrawable | undefined\n\tlet target: Store | null = store\n\twhile (target !== null) {\n\t\tswitch (token.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\twithdrawn = target.atoms.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `selector`:\n\t\t\t\twithdrawn = target.selectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `readonly_selector`:\n\t\t\t\twithdrawn = target.readonlySelectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `timeline`:\n\t\t\t\twithdrawn = target.timelines.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `transaction`:\n\t\t\t\twithdrawn = target.transactions.get(token.key)\n\t\t\t\tbreak\n\t\t}\n\t\tif (withdrawn) {\n\t\t\treturn withdrawn\n\t\t}\n\t\ttarget = target.child\n\t}\n}\n","import type {\n\tReadableToken,\n\tReadonlySelectorToken,\n\tRegularAtomToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type {\n\tAtom,\n\tReadableState,\n\tReadonlySelector,\n\tStore,\n\tWritableSelector,\n\tWritableState,\n} from \"..\"\nimport { newest, withdraw } from \"..\"\n\nexport function withdrawNewFamilyMember<T>(\n\ttoken: RegularAtomToken<T>,\n\tstore: Store,\n): Atom<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: WritableSelectorToken<T>,\n\tstore: Store,\n): WritableSelector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadonlySelectorToken<T>,\n\tstore: Store,\n): ReadonlySelector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: WritableToken<T>,\n\tstore: Store,\n): WritableState<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Store,\n): ReadableState<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Store,\n): ReadableState<T> | undefined {\n\tif (token.family) {\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ‘ช`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`creating new family member in store \"${store.config.name}\"`,\n\t\t)\n\t\tconst target = newest(store)\n\t\tconst family = target.families.get(token.family.key)\n\t\tif (family) {\n\t\t\tconst jsonSubKey = JSON.parse(token.family.subKey)\n\t\t\tfamily(jsonSubKey)\n\t\t\tconst state = withdraw(token, store)\n\t\t\treturn state\n\t\t}\n\t}\n\treturn undefined\n}\n","/**\n * A Promise that can be canceled.\n * @internal\n * @private\n * @typeParam T The type of the value that the promise will resolve to.\n *\n * @remarks\n * Can be constructed like a Promise, or from an existing Promise.\n */\nexport class Future<T> extends Promise<T> {\n\tpublic isCanceled = false\n\n\tpublic constructor(\n\t\texecutor:\n\t\t\t| Promise<T>\n\t\t\t| ((resolve: (value: T) => void, reject: (reason?: any) => void) => void),\n\t) {\n\t\tsuper((resolve, reject) => {\n\t\t\tconst pass = (value: T) =>\n\t\t\t\tthis.isCanceled ? reject(`canceled`) : resolve(value)\n\t\t\tconst fail = (reason: any) =>\n\t\t\t\tthis.isCanceled ? reject(`canceled`) : reject(reason)\n\t\t\tif (typeof executor === `function`) {\n\t\t\t\texecutor(pass, fail)\n\t\t\t} else {\n\t\t\t\texecutor.then(pass, fail)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic cancel(): void {\n\t\tthis.isCanceled = true\n\t}\n}\n","import type { MutableAtom, Transceiver } from \"..\"\nimport { Tracker } from \"../mutable\"\nimport type { Store } from \"../store\"\n\nexport function copyMutableIfNeeded<T extends Transceiver<any>>(\n\tatom: MutableAtom<T, any>,\n\torigin: Store,\n\ttarget: Store,\n): T {\n\tconst originValue = origin.valueMap.get(atom.key)\n\tconst targetValue = target.valueMap.get(atom.key)\n\tif (originValue === targetValue) {\n\t\torigin.logger.info(`๐Ÿ“ƒ`, `atom`, `${atom.key}`, `copying`)\n\t\tconst jsonValue = atom.toJson(originValue)\n\t\tconst copiedValue = atom.fromJson(jsonValue)\n\t\ttarget.valueMap.set(atom.key, copiedValue)\n\t\tnew Tracker(atom, origin)\n\t\treturn copiedValue\n\t}\n\treturn targetValue\n}\n","import { newest } from \"..\"\nimport type { Atom, Store } from \"..\"\nimport { copyMutableIfNeeded } from \"./copy-mutable-if-needed\"\n\nexport function copyMutableIfWithinTransaction<T>(\n\toldValue: T,\n\tatom: Atom<T>,\n\tstore: Store,\n): T {\n\tconst target = newest(store)\n\tconst parent = target.parent\n\tif (parent !== null) {\n\t\tif (atom.type === `mutable_atom`) {\n\t\t\tconst copiedValue = copyMutableIfNeeded(atom, parent, target)\n\t\t\treturn copiedValue\n\t\t}\n\t}\n\treturn oldValue\n}\n","import type { StateUpdate } from \"atom.io\"\nimport type { ReadableState } from \".\"\nimport { Future } from \"./future\"\nimport { copyMutableIfWithinTransaction } from \"./set-state/copy-mutable-in-transaction\"\nimport type { Store } from \"./store\"\nimport type { Subject } from \"./subject\"\n\nexport function cacheValue<T>(\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n\tstore: Store,\n): T\nexport function cacheValue<T extends Promise<any>>(\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n\tstore: Store,\n): Future<T>\nexport function cacheValue<T>(\n\tkey: string,\n\tvalue: T,\n\tsubject: Subject<StateUpdate<unknown>>,\n\ttarget: Store,\n): Future<T> | T {\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future) {\n\t\tcurrentValue.cancel()\n\t}\n\tif (value instanceof Promise) {\n\t\tconst future = new Future<T>(value)\n\t\ttarget.valueMap.set(key, future)\n\t\tfuture\n\t\t\t.then((resolved) => {\n\t\t\t\tif (future.isCanceled) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tcacheValue(key, resolved, subject, target)\n\t\t\t\tsubject.next({ newValue: resolved, oldValue: future })\n\t\t\t})\n\t\t\t.catch((thrown) => {\n\t\t\t\tif (thrown !== `canceled`) {\n\t\t\t\t\ttarget.logger.error(`๐Ÿ’ฅ`, `state`, key, `rejected:`, thrown)\n\t\t\t\t}\n\t\t\t})\n\t\treturn future\n\t}\n\ttarget.valueMap.set(key, value)\n\treturn value\n}\n\nexport const readCachedValue = <T>(\n\ttoken: ReadableState<any>,\n\ttarget: Store,\n): T => {\n\tlet value = target.valueMap.get(token.key) as T\n\tif (token.type === `atom`) {\n\t\tvalue = copyMutableIfWithinTransaction(value, token, target)\n\t}\n\treturn value\n}\n\nexport const evictCachedValue = (key: string, target: Store): void => {\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future) {\n\t\tcurrentValue.cancel()\n\t}\n\tif (target.operation.open) {\n\t\ttarget.operation.prev.set(key, currentValue)\n\t}\n\ttarget.valueMap.delete(key)\n\ttarget.logger.info(`๐Ÿ—‘`, `state`, key, `evicted`)\n}\n","import type { ReadableState } from \".\"\nimport { readCachedValue } from \"./caching\"\nimport type { Store } from \"./store\"\n\nexport const readOrComputeValue = <T>(\n\tstate: ReadableState<T>,\n\ttarget: Store,\n): T => {\n\tif (target.valueMap.has(state.key)) {\n\t\ttarget.logger.info(`๐Ÿ“–`, state.type, state.key, `reading cached value`)\n\t\treturn readCachedValue(state, target)\n\t}\n\tif (state.type !== `atom` && state.type !== `mutable_atom`) {\n\t\ttarget.logger.info(`๐Ÿงฎ`, state.type, state.key, `computing value`)\n\t\treturn state.get()\n\t}\n\tconst fallback =\n\t\tstate.default instanceof Function ? state.default() : state.default\n\ttarget.logger.info(\n\t\t`๐Ÿ’`,\n\t\t`atom`,\n\t\tstate.key,\n\t\t`could not find cached value; using default`,\n\t\tfallback,\n\t)\n\treturn state.default instanceof Function ? state.default() : state.default\n}\n","import type { Transactors, findState } from \"atom.io\"\nimport { findInStore } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { readOrComputeValue } from \"../read-or-compute-value\"\nimport { setAtomOrSelector } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { updateSelectorAtoms } from \"./update-selector-atoms\"\n\nexport const registerSelector = (\n\tselectorKey: string,\n\tstore: Store,\n): Transactors => ({\n\tget: (dependency) => {\n\t\tconst target = newest(store)\n\n\t\tconst dependencyState = withdraw(dependency, store)\n\t\tif (dependencyState === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${dependency.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t\t)\n\t\t}\n\t\tconst dependencyValue = readOrComputeValue(dependencyState, store)\n\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ”Œ`,\n\t\t\t`selector`,\n\t\t\tselectorKey,\n\t\t\t`registers dependency ( \"${dependency.key}\" =`,\n\t\t\tdependencyValue,\n\t\t\t`)`,\n\t\t)\n\n\t\ttarget.selectorGraph.set(\n\t\t\t{\n\t\t\t\tupstreamSelectorKey: dependency.key,\n\t\t\t\tdownstreamSelectorKey: selectorKey,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: dependency.key,\n\t\t\t},\n\t\t)\n\t\tupdateSelectorAtoms(selectorKey, dependency, store)\n\t\treturn dependencyValue\n\t},\n\tset: (WritableToken, newValue) => {\n\t\tconst state = withdraw(WritableToken, store)\n\t\tif (state === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${WritableToken.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t\t)\n\t\t}\n\t\tsetAtomOrSelector(state, newValue, store)\n\t},\n\tfind: ((token, key) => findInStore(token, key, store)) as typeof findState,\n})\n","export type Modify<T> = (thing: T) => T\n\nexport const become =\n\t<T>(nextVersionOfThing: Modify<T> | T) =>\n\t(originalThing: T): T =>\n\t\tnextVersionOfThing instanceof Function\n\t\t\t? nextVersionOfThing(\n\t\t\t\t\toriginalThing instanceof Function ? originalThing() : originalThing,\n\t\t\t )\n\t\t\t: nextVersionOfThing\n","import type { WritableToken } from \"atom.io\"\n\nimport { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\n\nexport type OperationProgress =\n\t| {\n\t\t\topen: false\n\t }\n\t| {\n\t\t\topen: true\n\t\t\tdone: Set<string>\n\t\t\tprev: Map<string, any>\n\t\t\ttime: number\n\t\t\ttoken: WritableToken<any>\n\t }\n\nexport const openOperation = (\n\ttoken: WritableToken<any>,\n\tstore: Store,\n): `rejection` | undefined => {\n\tif (store.operation.open) {\n\t\tstore.logger.error(\n\t\t\t`โŒ`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`failed to setState during a setState for \"${store.operation.token.key}\"`,\n\t\t)\n\t\treturn `rejection`\n\t}\n\tstore.operation = {\n\t\topen: true,\n\t\tdone: new Set(),\n\t\tprev: new Map(),\n\t\ttime: Date.now(),\n\t\ttoken,\n\t}\n\tstore.logger.info(\n\t\t`โญ•`,\n\t\ttoken.type,\n\t\ttoken.key,\n\t\t`operation start in store \"${store.config.name}\"${\n\t\t\tstore.transactionMeta === null\n\t\t\t\t? ``\n\t\t\t\t: ` ${store.transactionMeta.phase} \"${store.transactionMeta.update.key}\"`\n\t\t}`,\n\t)\n}\nexport const closeOperation = (store: Store): void => {\n\tif (store.operation.open) {\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ”ด`,\n\t\t\tstore.operation.token.type,\n\t\t\tstore.operation.token.key,\n\t\t\t`operation done in store \"${store.config.name}\"`,\n\t\t)\n\t}\n\tstore.operation = { open: false }\n\tstore.on.operationClose.next(store.operation)\n}\n\nexport const isDone = (key: string, store: Store): boolean => {\n\tif (!store.operation.open) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿž`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`isDone called outside of an operation. This is probably a bug.`,\n\t\t)\n\t\treturn true\n\t}\n\treturn store.operation.done.has(key)\n}\nexport const markDone = (key: string, store: Store): void => {\n\tif (!store.operation.open) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿž`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`markDone called outside of an operation. This is probably a bug.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.operation.done.add(key)\n}\n","import type { StateUpdate } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\n\nimport type { Atom, Selector } from \"..\"\n\nexport const emitUpdate = <T>(\n\tstate: Atom<T> | Selector<T>,\n\tupdate: StateUpdate<T>,\n\tstore: Store,\n): void => {\n\tstore.logger.info(\n\t\t`๐Ÿ“ข`,\n\t\tstate.type,\n\t\tstate.key,\n\t\t`went (`,\n\t\tupdate.oldValue,\n\t\t`->`,\n\t\tupdate.newValue,\n\t\t`) subscribers:`,\n\t\tstate.subject.subscribers,\n\t)\n\tstate.subject.next(update)\n}\n","import type { Atom } from \"..\"\nimport { evictCachedValue } from \"../caching\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Store } from \"../store\"\n\nexport const evictDownStream = <T>(atom: Atom<T>, store: Store): void => {\n\tconst downstreamKeys = store.selectorAtoms.getRelatedKeys(atom.key)\n\tstore.logger.info(\n\t\t`๐Ÿงน`,\n\t\tatom.type,\n\t\tatom.key,\n\t\tdownstreamKeys\n\t\t\t? `evicting ${downstreamKeys.size} states downstream:`\n\t\t\t: `no downstream states`,\n\t\tdownstreamKeys ?? `to evict`,\n\t)\n\tif (downstreamKeys) {\n\t\tif (store.operation.open) {\n\t\t\tstore.logger.info(\n\t\t\t\t`๐Ÿงน`,\n\t\t\t\tatom.type,\n\t\t\t\tatom.key,\n\t\t\t\t`[ ${[...store.operation.done].join(`, `)} ] already done`,\n\t\t\t)\n\t\t}\n\t\tfor (const key of downstreamKeys) {\n\t\t\tif (isDone(key, store)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tevictCachedValue(key, store)\n\t\t\tmarkDone(key, store)\n\t\t}\n\t}\n}\n","import type { KeyedStateUpdate, StateUpdate } from \"atom.io\"\n\nimport type { Atom } from \"..\"\nimport { newest } from \"../lineage\"\nimport { isTransceiver } from \"../mutable\"\nimport type { Store } from \"../store\"\n\nfunction shouldUpdateBeStowed(key: string, update: StateUpdate<any>): boolean {\n\t// do not stow updates that aren't json\n\tif (isTransceiver(update.newValue)) {\n\t\treturn false\n\t}\n\t// do not stow updates where the key contains ๐Ÿ‘โ€๐Ÿ—จ\n\tif (key.includes(`๐Ÿ‘โ€๐Ÿ—จ`)) {\n\t\treturn false\n\t}\n\treturn true\n}\n\nexport const stowUpdate = <T>(\n\tstate: Atom<T>,\n\tupdate: StateUpdate<T>,\n\tstore: Store,\n): void => {\n\tconst { key } = state\n\tconst target = newest(store)\n\tif (\n\t\ttarget.transactionMeta === null ||\n\t\ttarget.transactionMeta.phase !== `building`\n\t) {\n\t\tstore.logger.error(\n\t\t\t`๐Ÿž`,\n\t\t\t`atom`,\n\t\t\tkey,\n\t\t\t`stowUpdate called outside of a transaction. This is probably a bug.`,\n\t\t)\n\t\treturn\n\t}\n\tconst shouldStow = shouldUpdateBeStowed(key, update)\n\tif (!shouldStow) {\n\t\treturn\n\t}\n\tconst atomUpdate: KeyedStateUpdate<T> = { key, ...update }\n\tif (state.family) {\n\t\tatomUpdate.family = state.family\n\t}\n\ttarget.transactionMeta.update.updates.push(atomUpdate)\n\tstore.logger.info(\n\t\t`๐Ÿ“`,\n\t\t`atom`,\n\t\tkey,\n\t\t`stowed (`,\n\t\tupdate.oldValue,\n\t\t`->`,\n\t\tupdate.newValue,\n\t\t`)`,\n\t)\n}\n","import type { Atom } from \"..\"\nimport { isAtomDefault, markAtomAsNotDefault } from \"../atom\"\nimport { cacheValue } from \"../caching\"\nimport type { Transceiver } from \"../mutable\"\nimport { markDone } from \"../operation\"\nimport { readOrComputeValue } from \"../read-or-compute-value\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\nimport { copyMutableIfWithinTransaction } from \"./copy-mutable-in-transaction\"\nimport { emitUpdate } from \"./emit-update\"\nimport { evictDownStream } from \"./evict-downstream\"\nimport { stowUpdate } from \"./stow-update\"\n\nexport const setAtom = <T>(\n\tatom: Atom<T>,\n\tnext: T | ((oldValue: T) => T),\n\ttarget: Store,\n): void => {\n\tconst oldValue = readOrComputeValue(atom, target)\n\tlet newValue = copyMutableIfWithinTransaction(oldValue, atom, target)\n\tnewValue = become(next)(newValue)\n\ttarget.logger.info(`๐Ÿ“`, `atom`, atom.key, `set to`, newValue)\n\tnewValue = cacheValue(atom.key, newValue, atom.subject, target)\n\tif (isAtomDefault(atom.key, target)) {\n\t\tmarkAtomAsNotDefault(atom.key, target)\n\t}\n\tmarkDone(atom.key, target)\n\tevictDownStream(atom, target)\n\tconst update = { oldValue, newValue }\n\tif (target.transactionMeta === null) {\n\t\temitUpdate(atom, update, target)\n\t} else if (target.on.transactionApplying && target.parent) {\n\t\tstowUpdate(atom, update, target)\n\t\tif (atom.key.startsWith(`*`)) {\n\t\t\tconst mutableKey = atom.key.slice(1)\n\t\t\tconst mutable: Transceiver<any> = target.valueMap.get(mutableKey)\n\t\t\tmutable.do(update.newValue)\n\t\t}\n\t}\n}\n","import type { WritableState } from \"..\"\nimport type { Store } from \"../store\"\nimport { setAtom } from \"./set-atom\"\n\nexport const setAtomOrSelector = <T>(\n\tstate: WritableState<T>,\n\tvalue: T | ((oldValue: T) => T),\n\tstore: Store,\n): void => {\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tsetAtom(state, value, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\t\tstate.set(value)\n\t\t\tbreak\n\t}\n}\n","import { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\n\nexport type AtomKey<T> = string & { __atomKey?: never; __brand?: T }\nexport type SelectorKey<T> = string & { __selectorKey?: never; __brand?: T }\nexport type ReadonlySelectorKey<T> = string & {\n\t__readonlySelectorKey?: never\n\t__brand?: T\n}\n\nexport const isAtomKey = (key: string, store: Store): key is AtomKey<unknown> =>\n\tnewest(store).atoms.has(key)\nexport const isSelectorKey = (\n\tkey: string,\n\tstore: Store,\n): key is SelectorKey<unknown> => newest(store).selectors.has(key)\nexport const isReadonlySelectorKey = (\n\tkey: string,\n\tstore: Store,\n): key is ReadonlySelectorKey<unknown> =>\n\tnewest(store).readonlySelectors.has(key)\n\nexport type StateKey<T> = AtomKey<T> | ReadonlySelectorKey<T> | SelectorKey<T>\nexport const isStateKey = (\n\tkey: string,\n\tstore: Store,\n): key is StateKey<unknown> =>\n\tisAtomKey(key, store) ||\n\tisSelectorKey(key, store) ||\n\tisReadonlySelectorKey(key, store)\n","import type { AtomKey, ReadonlySelectorKey, SelectorKey } from \"../keys\"\nimport { isStateKey } from \"../keys\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const getSelectorDependencyKeys = (\n\tkey: string,\n\tstore: Store,\n): (\n\t| AtomKey<unknown>\n\t| ReadonlySelectorKey<unknown>\n\t| SelectorKey<unknown>\n)[] => {\n\tconst sources = newest(store)\n\t\t.selectorGraph.getRelationEntries({ downstreamSelectorKey: key })\n\t\t.filter(([_, { source }]) => source !== key)\n\t\t.map(([_, { source }]) => source)\n\t\t.filter((source) => isStateKey(source, store))\n\treturn sources\n}\n","import type { Selector, Store } from \"..\"\nimport type { AtomKey, StateKey } from \"../keys\"\nimport { isAtomKey } from \"../keys\"\nimport { getSelectorDependencyKeys } from \"./get-selector-dependency-keys\"\n\nexport const traceSelectorAtoms = (\n\tselectorKey: string,\n\tdirectDependencyKey: StateKey<unknown>,\n\tstore: Store,\n): AtomKey<unknown>[] => {\n\tconst rootKeys: AtomKey<unknown>[] = []\n\n\tconst indirectDependencyKeys = getSelectorDependencyKeys(\n\t\tdirectDependencyKey,\n\t\tstore,\n\t)\n\tlet depth = 0\n\twhile (indirectDependencyKeys.length > 0) {\n\t\t// biome-ignore lint/style/noNonNullAssertion: just checked length ^^^\n\t\tconst indirectDependencyKey = indirectDependencyKeys.shift()!\n\t\t++depth\n\t\tif (depth > 99999) {\n\t\t\tthrow new Error(\n\t\t\t\t`Maximum selector dependency depth exceeded (> 99999) in selector \"${selectorKey}\". This is likely due to a circular dependency.`,\n\t\t\t)\n\t\t}\n\n\t\tif (!isAtomKey(indirectDependencyKey, store)) {\n\t\t\tindirectDependencyKeys.push(\n\t\t\t\t...getSelectorDependencyKeys(indirectDependencyKey, store),\n\t\t\t)\n\t\t} else if (!rootKeys.includes(indirectDependencyKey)) {\n\t\t\trootKeys.push(indirectDependencyKey)\n\t\t}\n\t}\n\n\treturn rootKeys\n}\n\nexport const traceAllSelectorAtoms = (\n\tselector: Selector<any>,\n\tstore: Store,\n): AtomKey<unknown>[] => {\n\tconst selectorKey = selector.key\n\tconst directDependencyKeys = getSelectorDependencyKeys(selectorKey, store)\n\treturn directDependencyKeys.flatMap((depKey) =>\n\t\tisAtomKey(depKey, store)\n\t\t\t? depKey\n\t\t\t: traceSelectorAtoms(selectorKey, depKey, store),\n\t)\n}\n","import type { ReadonlySelectorToken, WritableToken } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { traceSelectorAtoms } from \"./trace-selector-atoms\"\n\nexport const updateSelectorAtoms = (\n\tselectorKey: string,\n\tdependency: ReadonlySelectorToken<unknown> | WritableToken<unknown>,\n\tstore: Store,\n): void => {\n\tconst target = newest(store)\n\tif (dependency.type === `atom` || dependency.type === `mutable_atom`) {\n\t\ttarget.selectorAtoms.set({\n\t\t\tselectorKey,\n\t\t\tatomKey: dependency.key,\n\t\t})\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ”`,\n\t\t\t`selector`,\n\t\t\tselectorKey,\n\t\t\t`discovers root atom \"${dependency.key}\"`,\n\t\t)\n\t} else {\n\t\tconst rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store)\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ”`,\n\t\t\t`selector`,\n\t\t\tselectorKey,\n\t\t\t`discovers root atoms: [ ${rootKeys\n\t\t\t\t.map((key) => `\"${key}\"`)\n\t\t\t\t.join(`, `)} ]`,\n\t\t)\n\t\tfor (const atomKey of rootKeys) {\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}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorOptions,\n\tReadonlySelectorToken,\n} from \"atom.io\"\n\nimport type { ReadonlySelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadonlySelector = <T>(\n\toptions: ReadonlySelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): ReadonlySelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\n\tconst { get, find } = registerSelector(options.key, target)\n\tconst getSelf = () => {\n\t\tconst value = options.get({ get, find })\n\t\tcacheValue(options.key, value, subject, newest(store))\n\t\treturn value\n\t}\n\n\tconst readonlySelector: ReadonlySelector<T> = {\n\t\t...options,\n\t\tsubject,\n\t\tinstall: (s: Store) => createReadonlySelector(options, family, s),\n\t\tget: getSelf,\n\t\ttype: `readonly_selector`,\n\t\t...(family && { family }),\n\t}\n\ttarget.readonlySelectors.set(options.key, readonlySelector)\n\tconst initialValue = getSelf()\n\tstore.logger.info(\n\t\t`โœจ`,\n\t\treadonlySelector.type,\n\t\treadonlySelector.key,\n\t\t`=`,\n\t\tinitialValue,\n\t)\n\tconst token: ReadonlySelectorToken<T> = {\n\t\tkey: options.key,\n\t\ttype: `readonly_selector`,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\tstore.on.selectorCreation.next(token)\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tWritableSelectorOptions,\n\tWritableSelectorToken,\n} from \"atom.io\"\n\nimport type { WritableSelector } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { markDone } from \"../operation\"\nimport { become } from \"../set-state/become\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createWritableSelector = <T>(\n\toptions: WritableSelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): WritableSelectorToken<T> => {\n\tconst target = newest(store)\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst transactors = registerSelector(options.key, target)\n\tconst { find, get } = transactors\n\tconst readonlyTransactors = { find, get }\n\n\tconst getSelf = () => {\n\t\tconst value = options.get(readonlyTransactors)\n\t\tcacheValue(options.key, value, subject, newest(store))\n\t\treturn value\n\t}\n\n\tconst setSelf = (next: T | ((oldValue: T) => T)): void => {\n\t\tconst oldValue = getSelf()\n\t\tconst newValue = become(next)(oldValue)\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ“`,\n\t\t\t`selector`,\n\t\t\toptions.key,\n\t\t\t`set (`,\n\t\t\toldValue,\n\t\t\t`->`,\n\t\t\tnewValue,\n\t\t\t`)`,\n\t\t)\n\t\tcacheValue(options.key, newValue, subject, store)\n\t\tmarkDone(options.key, store)\n\t\tif (target.transactionMeta === null) {\n\t\t\tsubject.next({ newValue, oldValue })\n\t\t}\n\t\toptions.set(transactors, newValue)\n\t}\n\tconst mySelector: WritableSelector<T> = {\n\t\t...options,\n\t\tsubject,\n\t\tinstall: (s: Store) => createWritableSelector(options, family, s),\n\t\tget: getSelf,\n\t\tset: setSelf,\n\t\ttype: `selector`,\n\t\t...(family && { family }),\n\t}\n\ttarget.selectors.set(options.key, mySelector)\n\tconst initialValue = getSelf()\n\tstore.logger.info(`โœจ`, mySelector.type, mySelector.key, `=`, initialValue)\n\tconst token: WritableSelectorToken<T> = {\n\t\tkey: options.key,\n\t\ttype: `selector`,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\tstore.on.selectorCreation.next(token)\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorOptions,\n\tReadonlySelectorToken,\n\tWritableSelectorOptions,\n\tWritableSelectorToken,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { createReadonlySelector } from \"./create-readonly-selector\"\nimport { createWritableSelector } from \"./create-writable-selector\"\n\nexport function createStandaloneSelector<T>(\n\toptions: WritableSelectorOptions<T>,\n\tstore: Store,\n): WritableSelectorToken<T>\nexport function createStandaloneSelector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n\tstore: Store,\n): ReadonlySelectorToken<T>\nexport function createStandaloneSelector<T>(\n\toptions: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,\n\tstore: Store,\n): ReadonlySelectorToken<T> | WritableSelectorToken<T> {\n\tconst isWritable = `set` in options\n\n\tif (isWritable) {\n\t\treturn createWritableSelector(options, undefined, store)\n\t}\n\treturn createReadonlySelector(options, undefined, store)\n}\n","import type { ReadonlySelectorToken, WritableSelectorToken } from \"atom.io\"\n\nimport { newest } from \"..\"\nimport type { Store } from \"..\"\n\nexport function deleteSelector(\n\tselectorToken: ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>,\n\tstore: Store,\n): void {\n\tconst target = newest(store)\n\tconst { key } = selectorToken\n\tswitch (selectorToken.type) {\n\t\tcase `selector`:\n\t\t\ttarget.selectors.delete(key)\n\t\t\tbreak\n\t\tcase `readonly_selector`:\n\t\t\ttarget.readonlySelectors.delete(key)\n\t\t\tbreak\n\t}\n\ttarget.valueMap.delete(key)\n\ttarget.selectorAtoms.delete(key)\n\tconst downstreamTokens = target.selectorGraph\n\t\t.getRelationEntries({ upstreamSelectorKey: key })\n\t\t.filter(([_, { source }]) => source === key)\n\t\t.map(\n\t\t\t([downstreamSelectorKey]) =>\n\t\t\t\ttarget.selectors.get(downstreamSelectorKey) ??\n\t\t\t\ttarget.readonlySelectors.get(downstreamSelectorKey),\n\t\t)\n\tfor (const downstreamToken of downstreamTokens) {\n\t\tif (downstreamToken) {\n\t\t\tdeleteSelector(downstreamToken, store)\n\t\t}\n\t}\n\ttarget.selectorGraph.delete(key)\n\tstore.logger.info(`๐Ÿ”ฅ`, selectorToken.type, `${key}`, `deleted`)\n}\n","import type { ReadableState } from \"..\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const recallState = <T>(state: ReadableState<T>, store: Store): T => {\n\tconst target = newest(store)\n\tif (!target.operation.open) {\n\t\treturn target.valueMap.get(state.key)\n\t}\n\treturn target.operation.prev.get(state.key)\n}\n","import type { Selector } from \"..\"\nimport { newest } from \"../lineage\"\nimport { readOrComputeValue } from \"../read-or-compute-value\"\nimport { traceAllSelectorAtoms } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { recallState } from \"./recall-state\"\n\nexport const subscribeToRootAtoms = <T>(\n\tselector: Selector<T>,\n\tstore: Store,\n): (() => void)[] | null => {\n\tconst target = newest(store)\n\tconst dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(\n\t\t(atomKey) => {\n\t\t\tconst atom = target.atoms.get(atomKey)\n\t\t\tif (atom === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Atom \"${atomKey}\", a dependency of selector \"${selector.key}\", not found in store \"${store.config.name}\".`,\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn atom.subject.subscribe(\n\t\t\t\t`${selector.type}:${selector.key}`,\n\t\t\t\t(atomChange) => {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`๐Ÿ“ข`,\n\t\t\t\t\t\tselector.type,\n\t\t\t\t\t\tselector.key,\n\t\t\t\t\t\t`root`,\n\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t`went`,\n\t\t\t\t\t\tatomChange.oldValue,\n\t\t\t\t\t\t`->`,\n\t\t\t\t\t\tatomChange.newValue,\n\t\t\t\t\t)\n\t\t\t\t\tconst oldValue = recallState(selector, target)\n\t\t\t\t\tconst newValue = readOrComputeValue(selector, target)\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`โœจ`,\n\t\t\t\t\t\tselector.type,\n\t\t\t\t\t\tselector.key,\n\t\t\t\t\t\t`went`,\n\t\t\t\t\t\toldValue,\n\t\t\t\t\t\t`->`,\n\t\t\t\t\t\tnewValue,\n\t\t\t\t\t)\n\t\t\t\t\tselector.subject.next({ newValue, oldValue })\n\t\t\t\t},\n\t\t\t)\n\t\t},\n\t)\n\treturn dependencySubscriptions\n}\n","import type { ReadableToken, UpdateHandler } from \"atom.io\"\nimport type { Store } from \"../store\"\nimport { withdraw, withdrawNewFamilyMember } from \"../store\"\nimport { subscribeToRootAtoms } from \"./subscribe-to-root-atoms\"\n\nexport function subscribeToState<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string,\n\tstore: Store,\n): () => void {\n\tconst state =\n\t\twithdraw<T>(token, store) ?? withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.logger.info(`๐Ÿ‘€`, state.type, state.key, `Adding subscription \"${key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` && state.type !== `mutable_atom`\n\t\t\t? subscribeToRootAtoms(state, store)\n\t\t\t: null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`๐Ÿ™ˆ`,\n\t\t\t\t\t\tstate.type,\n\t\t\t\t\t\tstate.key,\n\t\t\t\t\t\t`Removing subscription \"${key}\"`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`๐Ÿ™ˆ`,\n\t\t\t\t\t\tstate.type,\n\t\t\t\t\t\tstate.key,\n\t\t\t\t\t\t`Removing subscription \"${key}\"`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n","import type { TimelineManageable, TimelineToken, TimelineUpdate } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { withdraw } from \"atom.io/internal\"\n\nexport const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(\n\ttoken: TimelineToken<ManagedAtom>,\n\thandleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void,\n\tkey: string,\n\tstore: Store,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.logger.info(`๐Ÿ‘€`, `timeline`, token.key, `Adding subscription \"${key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ™ˆ`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Removing subscription \"${key}\" from timeline`,\n\t\t)\n\t\tunsubscribe()\n\t}\n}\n","import type { TransactionToken, TransactionUpdateHandler, ฦ’n } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { withdraw } from \"atom.io/internal\"\n\nexport const subscribeToTransaction = <ฦ’ extends ฦ’n>(\n\ttoken: TransactionToken<ฦ’>,\n\thandleUpdate: TransactionUpdateHandler<ฦ’>,\n\tkey: string,\n\tstore: Store,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.logger.info(\n\t\t`๐Ÿ‘€`,\n\t\t`transaction`,\n\t\ttoken.key,\n\t\t`Adding subscription \"${key}\"`,\n\t)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ™ˆ`,\n\t\t\t`transaction`,\n\t\t\ttoken.key,\n\t\t\t`Removing subscription \"${key}\"`,\n\t\t)\n\t\tunsubscribe()\n\t}\n}\n","import type { FamilyMetadata, MutableAtomToken, RegularAtomToken } from \"atom.io\"\nimport { getState, setState } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"..\"\nimport { newest, subscribeToState, subscribeToTimeline } from \"..\"\nimport { createRegularAtom } from \"../atom\"\nimport type { Transceiver } from \"./transceiver\"\n\n/**\n * @internal Give the tracker a transceiver state and a store, and it will\n * subscribe to the transceiver's inner value. When the inner value changes,\n * the tracker will update its own state to reflect the change.\n */\nexport class Tracker<Mutable extends Transceiver<any>> {\n\tprivate Update: Mutable extends Transceiver<infer Signal> ? Signal : never\n\n\tprivate initializeState(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store,\n\t): RegularAtomToken<typeof this.Update | null> {\n\t\tconst latestUpdateStateKey = `*${mutableState.key}`\n\t\tstore.atoms.delete(latestUpdateStateKey)\n\t\tstore.valueMap.delete(latestUpdateStateKey)\n\t\tconst familyMetaData: FamilyMetadata | undefined = mutableState.family\n\t\t\t? {\n\t\t\t\t\tkey: `*${mutableState.family.key}`,\n\t\t\t\t\tsubKey: mutableState.family.subKey,\n\t\t\t }\n\t\t\t: undefined\n\t\tconst latestUpdateState = createRegularAtom<\n\t\t\t(Mutable extends Transceiver<infer Signal> ? Signal : never) | null\n\t\t>(\n\t\t\t{\n\t\t\t\tkey: latestUpdateStateKey,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\tfamilyMetaData,\n\t\t\tstore,\n\t\t)\n\t\tif (store.parent?.valueMap.has(latestUpdateStateKey)) {\n\t\t\tconst parentValue = store.parent.valueMap.get(latestUpdateStateKey)\n\t\t\tstore.valueMap.set(latestUpdateStateKey, parentValue)\n\t\t}\n\n\t\treturn latestUpdateState\n\t}\n\n\tprivate unsubscribeFromInnerValue: () => void\n\tprivate unsubscribeFromState: () => void\n\tprivate observeCore(\n\t\tmutableState: MutableAtomToken<Mutable, any>,\n\t\tlatestUpdateState: RegularAtomToken<typeof this.Update | null>,\n\t\tstore: Store,\n\t): void {\n\t\tconst originalInnerValue = getState(mutableState, store)\n\t\tconst target = newest(store)\n\t\tthis.unsubscribeFromInnerValue = originalInnerValue.subscribe(\n\t\t\t`tracker:${store.config.name}:${\n\t\t\t\ttarget.transactionMeta === null\n\t\t\t\t\t? `main`\n\t\t\t\t\t: target.transactionMeta.update.key\n\t\t\t}`,\n\t\t\t(update) => {\n\t\t\t\tif (target.operation.open) {\n\t\t\t\t\tconst unsubscribe = target.on.operationClose.subscribe(\n\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\tsetState(latestUpdateState, update, target)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tsetState(mutableState, (current) => current, target)\n\t\t\t\t\tsetState(latestUpdateState, update, target)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tthis.unsubscribeFromState = subscribeToState(\n\t\t\tmutableState,\n\t\t\t(update) => {\n\t\t\t\tif (update.newValue !== update.oldValue) {\n\t\t\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\t\t\tconst target = newest(store)\n\t\t\t\t\tthis.unsubscribeFromInnerValue = update.newValue.subscribe(\n\t\t\t\t\t\t`tracker:${store.config.name}:${\n\t\t\t\t\t\t\ttarget.transactionMeta === null\n\t\t\t\t\t\t\t\t? `main`\n\t\t\t\t\t\t\t\t: target.transactionMeta.update.key\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\tif (target.operation.open) {\n\t\t\t\t\t\t\t\tconst unsubscribe = target.on.operationClose.subscribe(\n\t\t\t\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\t\t\tsetState(latestUpdateState, update, target)\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetState(mutableState, (current) => current, target)\n\t\t\t\t\t\t\t\tsetState(latestUpdateState, update, target)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t\t`${store.config.name}: tracker observing inner value`,\n\t\t\tstore,\n\t\t)\n\t}\n\n\tprivate updateCore<Core extends Transceiver<any>>(\n\t\tmutableState: MutableAtomToken<Core, Json.Serializable>,\n\t\tlatestUpdateState: RegularAtomToken<typeof this.Update | null>,\n\t\tstore: Store,\n\t): void {\n\t\tsubscribeToState(\n\t\t\tlatestUpdateState,\n\t\t\t({ newValue, oldValue }) => {\n\t\t\t\tconst timelineId = store.timelineAtoms.getRelatedKey(\n\t\t\t\t\tlatestUpdateState.key,\n\t\t\t\t)\n\t\t\t\tif (timelineId) {\n\t\t\t\t\tconst timelineData = store.timelines.get(timelineId)\n\t\t\t\t\tif (timelineData?.timeTraveling) {\n\t\t\t\t\t\tconst unsubscribe = subscribeToTimeline(\n\t\t\t\t\t\t\t{ key: timelineId, type: `timeline` },\n\t\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\tsetState(\n\t\t\t\t\t\t\t\t\tmutableState,\n\t\t\t\t\t\t\t\t\t(transceiver) => {\n\t\t\t\t\t\t\t\t\t\tif (update === `redo` && newValue) {\n\t\t\t\t\t\t\t\t\t\t\ttransceiver.do(newValue)\n\t\t\t\t\t\t\t\t\t\t} else if (update === `undo` && oldValue) {\n\t\t\t\t\t\t\t\t\t\t\ttransceiver.undo(oldValue)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn transceiver\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t`${mutableState.key}: tracker observing timeline`,\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t\t\tlatestUpdateState.key,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\tconst mutable = getState(mutableState, store)\n\t\t\t\t\t\t// debugger\n\t\t\t\t\t\tconst updateNumber =\n\t\t\t\t\t\t\tnewValue === null ? -1 : mutable.getUpdateNumber(newValue)\n\t\t\t\t\t\tconst eventOffset = updateNumber - mutable.cacheUpdateNumber\n\t\t\t\t\t\tif (newValue && eventOffset === 1) {\n\t\t\t\t\t\t\t// โ— new:\"0=add:\\\"myHand\\\"\",old:\"0=add:\\\"deckId\\\"\"\n\t\t\t\t\t\t\tsetState(\n\t\t\t\t\t\t\t\tmutableState,\n\t\t\t\t\t\t\t\t(transceiver) => (transceiver.do(newValue), transceiver),\n\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t},\n\t\t\t`${store.config.name}: tracker observing latest update`,\n\t\t\tstore,\n\t\t)\n\t}\n\n\tpublic mutableState: MutableAtomToken<Mutable, Json.Serializable>\n\tpublic latestUpdateState: RegularAtomToken<typeof this.Update | null>\n\n\tpublic dispose: () => void\n\n\tpublic constructor(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store,\n\t) {\n\t\tthis.mutableState = mutableState\n\t\tconst target = newest(store)\n\t\tthis.latestUpdateState = this.initializeState(mutableState, target)\n\t\tthis.observeCore(mutableState, this.latestUpdateState, target)\n\t\tthis.updateCore(mutableState, this.latestUpdateState, target)\n\t\ttarget.trackers.set(mutableState.key, this)\n\t\tthis.dispose = () => {\n\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\tthis.unsubscribeFromState()\n\t\t\ttarget.trackers.delete(mutableState.key)\n\t\t}\n\t}\n}\n","import type {\n\tMutableAtomFamily,\n\tMutableAtomFamilyOptions,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n} from \"atom.io\"\nimport type { FamilyMetadata } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJsonFamily } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport { createMutableAtom } from \"../mutable\"\nimport { deposit, withdraw } from \"../store\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { FamilyTracker } from \"./tracker-family\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends string,\n>(\n\toptions: MutableAtomFamilyOptions<T, J, K>,\n\tstore: Store,\n): MutableAtomFamily<T, J, K> {\n\tconst subject = new Subject<MutableAtomToken<T, J>>()\n\tconst atomFamily: MutableAtomFamily<T, J, K> = Object.assign(\n\t\t(key: K): MutableAtomToken<T, J> => {\n\t\t\tconst subKey = stringifyJson(key)\n\t\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\t\tconst fullKey = `${options.key}(${subKey})`\n\t\t\tconst existing = withdraw({ key: fullKey, type: `mutable_atom` }, store)\n\t\t\tlet token: MutableAtomToken<T, J>\n\t\t\tif (existing) {\n\t\t\t\ttoken = deposit(existing)\n\t\t\t} else {\n\t\t\t\tconst individualOptions: MutableAtomOptions<T, J> = {\n\t\t\t\t\tkey: fullKey,\n\t\t\t\t\tdefault: () => options.default(key),\n\t\t\t\t\ttoJson: options.toJson,\n\t\t\t\t\tfromJson: options.fromJson,\n\t\t\t\t\tmutable: true,\n\t\t\t\t}\n\t\t\t\tif (options.effects) {\n\t\t\t\t\tindividualOptions.effects = options.effects(key)\n\t\t\t\t}\n\n\t\t\t\ttoken = createMutableAtom(individualOptions, family, store)\n\n\t\t\t\tsubject.next(token)\n\t\t\t}\n\t\t\treturn token\n\t\t},\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `mutable_atom_family`,\n\t\t\tsubject,\n\t\t\tinstall: (store: Store) => createMutableAtomFamily(options, store),\n\t\t\ttoJson: options.toJson,\n\t\t\tfromJson: options.fromJson,\n\t\t} as const,\n\t)\n\n\tconst target = newest(store)\n\ttarget.families.set(options.key, atomFamily)\n\tselectJsonFamily(atomFamily, options, store)\n\tnew FamilyTracker(atomFamily, store)\n\treturn atomFamily\n}\n","import type { MutableAtomFamily, RegularAtomFamily } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport { createRegularAtomFamily } from \"../families\"\nimport type { Store } from \"../store\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport class FamilyTracker<\n\tCore extends Transceiver<any>,\n\tFamilyMemberKey extends Json.Serializable,\n> {\n\tprivate readonly Update: Core extends Transceiver<infer Signal>\n\t\t? Signal\n\t\t: never\n\n\tpublic readonly findLatestUpdateState: RegularAtomFamily<\n\t\ttypeof this.Update | null,\n\t\tFamilyMemberKey\n\t>\n\tpublic readonly findMutableState: MutableAtomFamily<Core, any, FamilyMemberKey>\n\n\tpublic constructor(\n\t\tfindMutableState: MutableAtomFamily<Core, any, FamilyMemberKey>,\n\t\tstore: Store,\n\t) {\n\t\tthis.findLatestUpdateState = createRegularAtomFamily<\n\t\t\ttypeof this.Update | null,\n\t\t\tFamilyMemberKey\n\t\t>(\n\t\t\t{\n\t\t\t\tkey: `*${findMutableState.key}`,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\tthis.findMutableState = findMutableState\n\t\tthis.findMutableState.subject.subscribe(\n\t\t\t`store=${store.config.name}::tracker-atom-family`,\n\t\t\t(atomToken) => {\n\t\t\t\tif (atomToken.family) {\n\t\t\t\t\tconst key = parseJson(atomToken.family.subKey) as FamilyMemberKey\n\t\t\t\t\tthis.findLatestUpdateState(key)\n\t\t\t\t\tnew Tracker<Core>(atomToken, store)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tthis.findLatestUpdateState.subject.subscribe(\n\t\t\t`store=${store.config.name}::tracker-atom-family`,\n\t\t\t(atomToken) => {\n\t\t\t\tif (atomToken.family) {\n\t\t\t\t\tconst key = parseJson(atomToken.family.subKey) as FamilyMemberKey\n\t\t\t\t\tconst mutableAtomToken = this.findMutableState(key)\n\t\t\t\t\tnew Tracker<Core>(mutableAtomToken, store)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tRegularAtomFamily,\n\tRegularAtomFamilyOptions,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createRegularAtom } from \"../atom\"\nimport { newest } from \"../lineage\"\nimport { deposit, withdraw } from \"../store\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createRegularAtomFamily<T, K extends Json.Serializable>(\n\toptions: RegularAtomFamilyOptions<T, K>,\n\tstore: Store,\n): RegularAtomFamily<T, K> {\n\tconst subject = new Subject<RegularAtomToken<T>>()\n\tconst atomFamily: RegularAtomFamily<T, K> = Object.assign(\n\t\t(key: K): RegularAtomToken<any> => {\n\t\t\tconst subKey = stringifyJson(key)\n\t\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\t\tconst fullKey = `${options.key}(${subKey})`\n\t\t\tconst existing = withdraw({ key: fullKey, type: `atom` }, store)\n\t\t\tlet token: RegularAtomToken<any>\n\t\t\tif (existing) {\n\t\t\t\ttoken = deposit(existing)\n\t\t\t} else {\n\t\t\t\tconst individualOptions: RegularAtomOptions<any> = {\n\t\t\t\t\tkey: fullKey,\n\t\t\t\t\tdefault:\n\t\t\t\t\t\toptions.default instanceof Function\n\t\t\t\t\t\t\t? options.default(key)\n\t\t\t\t\t\t\t: options.default,\n\t\t\t\t}\n\t\t\t\tif (options.effects) {\n\t\t\t\t\tindividualOptions.effects = options.effects(key)\n\t\t\t\t}\n\t\t\t\ttoken = createRegularAtom(individualOptions, family, store)\n\t\t\t\tsubject.next(token)\n\t\t\t}\n\t\t\treturn token\n\t\t},\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `atom_family`,\n\t\t\tsubject,\n\t\t\tinstall: (store: Store) => createRegularAtomFamily(options, store),\n\t\t} as const,\n\t)\n\tconst target = newest(store)\n\ttarget.families.set(options.key, atomFamily)\n\treturn atomFamily\n}\n","import type {\n\tMutableAtomFamily,\n\tMutableAtomFamilyOptions,\n\tRegularAtomFamily,\n\tRegularAtomFamilyOptions,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { type Transceiver, createMutableAtomFamily } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { createRegularAtomFamily } from \"./create-regular-atom-family\"\n\nexport function createAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(\n\toptions: MutableAtomFamilyOptions<T, J, K>,\n\tstore: Store,\n): MutableAtomFamily<T, J, K>\nexport function createAtomFamily<T, K extends Json.Serializable>(\n\toptions: RegularAtomFamilyOptions<T, K>,\n\tstore: Store,\n): RegularAtomFamily<T, K>\nexport function createAtomFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t| RegularAtomFamilyOptions<T, K>,\n\tstore: Store,\n): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\tconst isMutable = `mutable` in options\n\n\tif (isMutable) {\n\t\treturn createMutableAtomFamily(options, store)\n\t}\n\treturn createRegularAtomFamily<T, K>(options, store)\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorFamily,\n\tReadonlySelectorFamilyOptions,\n\tReadonlySelectorToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport { createReadonlySelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createReadonlySelectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n\tstore: Store,\n): ReadonlySelectorFamily<T, K> {\n\tconst subject = new Subject<ReadonlySelectorToken<T>>()\n\tconst readonlySelectorFamily = Object.assign(\n\t\t(key: K): ReadonlySelectorToken<T> => {\n\t\t\tconst target = newest(store)\n\t\t\tconst subKey = stringifyJson(key)\n\t\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\t\tconst fullKey = `${options.key}(${subKey})`\n\t\t\tconst existing = target.readonlySelectors.get(fullKey)\n\t\t\tif (existing) {\n\t\t\t\treturn deposit(existing)\n\t\t\t}\n\t\t\treturn createReadonlySelector(\n\t\t\t\t{\n\t\t\t\t\tkey: fullKey,\n\t\t\t\t\tget: options.get(key),\n\t\t\t\t},\n\t\t\t\tfamily,\n\t\t\t\tstore,\n\t\t\t) as ReadonlySelectorToken<T>\n\t\t},\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `readonly_selector_family`,\n\t\t\tsubject,\n\t\t\tinstall: (store: Store) => createReadonlySelectorFamily(options, store),\n\t\t} as const,\n\t) as ReadonlySelectorFamily<T, K>\n\tstore.families.set(options.key, readonlySelectorFamily)\n\treturn readonlySelectorFamily\n}\n","import type {\n\tFamilyMetadata,\n\tWritableSelectorFamily,\n\tWritableSelectorFamilyOptions,\n\tWritableSelectorToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createWritableSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function createWritableSelectorFamily<T, K extends Json.Serializable>(\n\toptions: WritableSelectorFamilyOptions<T, K>,\n\tstore: Store,\n): WritableSelectorFamily<T, K> {\n\tconst subject = new Subject<WritableSelectorToken<T>>()\n\n\tconst selectorFamily = Object.assign(\n\t\t(key: K): WritableSelectorToken<T> => {\n\t\t\tconst subKey = stringifyJson(key)\n\t\t\tconst family: FamilyMetadata = { key: options.key, subKey }\n\t\t\tconst fullKey = `${options.key}(${subKey})`\n\t\t\tconst existing = store.selectors.get(fullKey)\n\t\t\tif (existing) {\n\t\t\t\treturn deposit(existing)\n\t\t\t}\n\t\t\tconst token = createWritableSelector(\n\t\t\t\t{\n\t\t\t\t\tkey: fullKey,\n\t\t\t\t\tget: options.get(key),\n\t\t\t\t\tset: options.set(key),\n\t\t\t\t},\n\t\t\t\tfamily,\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tsubject.next(token)\n\t\t\treturn token\n\t\t},\n\t\t{\n\t\t\tkey: options.key,\n\t\t\ttype: `selector_family`,\n\t\t\tsubject,\n\t\t\tinstall: (store: Store) => createWritableSelectorFamily(options, store),\n\t\t} as const,\n\t) as WritableSelectorFamily<T, K>\n\tstore.families.set(options.key, selectorFamily)\n\treturn selectorFamily\n}\n","import type {\n\tReadonlySelectorFamily,\n\tReadonlySelectorFamilyOptions,\n\tWritableSelectorFamily,\n\tWritableSelectorFamilyOptions,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { createReadonlySelectorFamily } from \"./create-readonly-selector-family\"\nimport { createWritableSelectorFamily } from \"./create-writable-selector-family\"\n\nexport function createSelectorFamily<T, K extends Json.Serializable>(\n\toptions: WritableSelectorFamilyOptions<T, K>,\n\tstore: Store,\n): WritableSelectorFamily<T, K>\nexport function createSelectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n\tstore: Store,\n): ReadonlySelectorFamily<T, K>\nexport function createSelectorFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| ReadonlySelectorFamilyOptions<T, K>\n\t\t| WritableSelectorFamilyOptions<T, K>,\n\tstore: Store,\n): ReadonlySelectorFamily<T, K> | WritableSelectorFamily<T, K> {\n\tconst isWritable = `set` in options\n\n\tif (isWritable) {\n\t\treturn createWritableSelectorFamily(options, store)\n\t}\n\treturn createReadonlySelectorFamily(options, store)\n}\n","import type { MutableAtomFamily, WritableSelectorFamily } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonFamily = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends string,\n>(\n\tmutableAtomFamily: MutableAtomFamily<Core, SerializableCore, Key>,\n\tstore: Store,\n): WritableSelectorFamily<SerializableCore, Key> => {\n\tconst target = newest(store)\n\tconst key = `${mutableAtomFamily.key}:JSON`\n\tconst jsonFamily: WritableSelectorFamily<SerializableCore, Key> =\n\t\ttarget.families.get(key) as WritableSelectorFamily<SerializableCore, Key>\n\treturn jsonFamily\n}\n","import type { MutableAtomToken, WritableSelectorToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonToken = <\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): WritableSelectorToken<SerializableCore> => {\n\tconst key = mutableAtomToken.family\n\t\t? `${mutableAtomToken.family.key}:JSON(${mutableAtomToken.family.subKey})`\n\t\t: `${mutableAtomToken.key}:JSON`\n\tconst jsonToken: WritableSelectorToken<SerializableCore> = {\n\t\ttype: `selector`,\n\t\tkey,\n\t}\n\tif (mutableAtomToken.family) {\n\t\tjsonToken.family = {\n\t\t\tkey: `${mutableAtomToken.family.key}:JSON`,\n\t\t\tsubKey: mutableAtomToken.family.subKey,\n\t\t}\n\t}\n\treturn jsonToken\n}\n","import type { MutableAtomToken, RegularAtomToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport type { Signal, Transceiver } from \"./transceiver\"\n\nexport const getUpdateToken = <\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): RegularAtomToken<Signal<Core>> => {\n\tconst key = `*${mutableAtomToken.key}`\n\tconst updateToken: RegularAtomToken<Signal<Core>> = { type: `atom`, key }\n\tif (mutableAtomToken.family) {\n\t\tupdateToken.family = {\n\t\t\tkey: `*${mutableAtomToken.family.key}`,\n\t\t\tsubKey: mutableAtomToken.family.subKey,\n\t\t}\n\t}\n\treturn updateToken\n}\n","import type { AtomFamily, MutableAtomFamily } from \"atom.io\"\n\nimport type { Atom, MutableAtom } from \"..\"\n\nexport function isMutable(atom: Atom<any>): atom is MutableAtom<any, any>\nexport function isMutable(\n\tfamily: AtomFamily<any, any>,\n): family is MutableAtomFamily<any, any, any>\nexport function isMutable(\n\tatomOrTokenOrFamily: Atom<any> | AtomFamily<any, any>,\n): boolean {\n\treturn (\n\t\tatomOrTokenOrFamily.type === `mutable_atom` ||\n\t\tatomOrTokenOrFamily.type === `mutable_atom_family`\n\t)\n}\n","import type { Json } from \"atom.io/json\"\n\nexport interface Transceiver<Signal extends Json.Serializable> {\n\tdo: (update: Signal) => void\n\tundo: (update: Signal) => void\n\tsubscribe: (key: string, fn: (update: Signal) => void) => () => void\n\tcacheUpdateNumber: number\n\tgetUpdateNumber: (update: Signal) => number\n}\n\nexport function isTransceiver(\n\tvalue: unknown,\n): value is Transceiver<Json.Serializable> {\n\treturn (\n\t\ttypeof value === `object` &&\n\t\tvalue !== null &&\n\t\t`do` in value &&\n\t\t`undo` in value &&\n\t\t`subscribe` in value\n\t)\n}\n\nexport type TransceiverMode = `playback` | `record` | `transaction`\n\nexport type Signal<TVR extends Transceiver<any>> = TVR extends Transceiver<\n\tinfer Signal\n>\n\t? Signal\n\t: never\n\n/*\nA transceiver may also keep a list of updates that have been applied to it.\nThis is useful for undo/redo functionality, especially in the context of\nrevising history. It is a good idea to accept a cache limit in your \nconstructor, and overwrite old updates. Here's an example of how we \nmight set that up:\n\nmyTransceiver = Transceiver {\n\tcacheUpdateNumber: number = 27\n\tcacheIdx: number = 1\n\tcacheLimit: number = 3\n\tcache: Array<Update> = [\n\t\t26=add:\"x\"\n\t\t27=del:\"x\" (current)\n\t\t25=add:\"y\"\n\t]\n}\n\nCONFIRM/NO-OP\nUpdate `27=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 27, update = `del:\"x\"`]\t\n- updateOffset = updateNumber - cacheUpdateNumber // 0\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // 1\n- update === cache.get(eventIdx) // true\n- return null // ๐Ÿ‘\n\nEXPECTED UPDATE\nUpdate `28=add:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 28, update = `add:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 1\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // true (we're ready to apply this update)\n- cacheIdx += eventOffset // 2\n- cacheIdx %= cacheLimit // 2\n- cache[cacheIdx] = update // cache = <{ 0 => add:\"x\" }>\n- return null // ๐Ÿ‘\n\nUNEXPECTED UPDATE\nUpdate `29=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 29, update = `del:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 2\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // false (we're NOT ready to apply this update)\n- updateIdx := cacheIdx + updateOffset // 3\n- updateIdx %= cacheLimit // 0\n- cache[updateIdx] = update // cache = <{ 0 => del:\"x\" }> \n- expectedUpdateNumber = cacheUpdateNumber + 1 // 28\n- return expectedUpdateNumber // ๐Ÿคจ๐Ÿ‘‚\n\nSUCCESSFUL ROLLBACK UPDATE\nUpdate `25=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 25, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -2\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // -1\n- eventIdx %= cacheLimit // 2\n- update === cache[eventIdx] // false (we're rolling back)\n- done := false\n- update := cache[cacheIdx] // update = `del:\"x\"`\n- undo(update) // myTransceiver.undo(`del:\"x\"`)\n- while (!done) {\n- \tcacheIdx -= 1 // 0, -1\n- \tcacheIdx %= cacheLimit // 0, 2\n- \tupdate = cache[cacheIdx] // update = `add:\"y\"`, `add:\"x\"`\n- \tundo(update) // myTransceiver.undo(`add:\"y\"`), myTransceiver.undo(`add:\"x\"`)\n- \tdone = cacheIdx === eventIdx // false, true\n- }\n- do(update) // myTransceiver.do(`add:\"z\"`)\n- return null // ๐Ÿ‘\n\nUNSUCCESSFUL ROLLBACK UPDATE\nUpdate `24=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 24, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -3\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // 3 < 3 // false (we don't remember this update)\n- return `OUT_OF_RANGE` // ๐Ÿ˜ตโ€๐Ÿ’ซ๐Ÿ‘‚\n\n*/\n","import type {\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport type { RegularAtom } from \"..\"\nimport { cacheValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport { markAtomAsDefault } from \"./is-default\"\n\nexport function createRegularAtom<T>(\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): RegularAtomToken<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 existing = target.atoms.get(options.key)\n\tif (existing && existing.type === `atom`) {\n\t\tstore.logger.error(\n\t\t\t`โŒ`,\n\t\t\t`atom`,\n\t\t\toptions.key,\n\t\t\t`Tried to create atom, but it already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: RegularAtom<T> = {\n\t\t...options,\n\t\ttype: `atom`,\n\t\tinstall: (store: Store) => {\n\t\t\tstore.logger.info(\n\t\t\t\t`๐Ÿ› ๏ธ`,\n\t\t\t\t`atom`,\n\t\t\t\toptions.key,\n\t\t\t\t`installing in store \"${store.config.name}\"`,\n\t\t\t)\n\t\t\treturn createRegularAtom(options, family, store)\n\t\t},\n\t\tsubject,\n\t} as const\n\tif (family) {\n\t\tnewAtom.family = family\n\t}\n\tlet initialValue = options.default\n\tif (options.default instanceof Function) {\n\t\tinitialValue = options.default()\n\t}\n\ttarget.atoms.set(newAtom.key, newAtom)\n\tmarkAtomAsDefault(options.key, store)\n\tcacheValue(options.key, initialValue, subject, target)\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\tsetSelf: (next) => setState(token, next, store),\n\t\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\t\tsubscribeToState(token, handle, `effect[${effectIndex}]`, store),\n\t\t\t})\n\t\t\tif (cleanup) {\n\t\t\t\tcleanupFunctions.push(cleanup)\n\t\t\t}\n\t\t\t++effectIndex\n\t\t}\n\t\tnewAtom.cleanup = () => {\n\t\t\tfor (const cleanup of cleanupFunctions) {\n\t\t\t\tcleanup()\n\t\t\t}\n\t\t}\n\t}\n\tstore.on.atomCreation.next(token)\n\treturn token\n}\n","import { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const isAtomDefault = (key: string, store: Store): boolean => {\n\tconst core = newest(store)\n\treturn core.atomsThatAreDefault.has(key)\n}\n\nexport const markAtomAsDefault = (key: string, store: Store): void => {\n\tconst core = newest(store)\n\tcore.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key)\n}\n\nexport const markAtomAsNotDefault = (key: string, store: Store): void => {\n\tconst core = newest(store)\n\tcore.atomsThatAreDefault = new Set(newest(store).atomsThatAreDefault)\n\tcore.atomsThatAreDefault.delete(key)\n}\n","import type {\n\tAtomToken,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport { createMutableAtom } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { createRegularAtom } from \"./create-regular-atom\"\n\nexport function createStandaloneAtom<T>(\n\toptions: RegularAtomOptions<T>,\n\tstore: Store,\n): RegularAtomToken<T>\nexport function createStandaloneAtom<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(options: MutableAtomOptions<T, J>, store: Store): MutableAtomToken<T, J>\nexport function createStandaloneAtom<T>(\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n\tstore: Store,\n): AtomToken<T> {\n\tconst isMutable = `mutable` in options\n\n\tif (isMutable) {\n\t\treturn createMutableAtom(options, undefined, store)\n\t}\n\treturn createRegularAtom(options, undefined, store)\n}\n","import type { RegularAtomToken } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { deleteSelector, newest } from \"..\"\n\nexport function deleteAtom(\n\tatomToken: RegularAtomToken<unknown>,\n\tstore: Store,\n): void {\n\tconst target = newest(store)\n\tconst { key } = atomToken\n\tconst atom = target.atoms.get(key)\n\tif (!atom) {\n\t\tstore.logger.error(\n\t\t\t`โŒ`,\n\t\t\t`atom`,\n\t\t\t`${key}`,\n\t\t\t`Tried to delete atom, but it does not exist in the store.`,\n\t\t)\n\t}\n\tatom?.cleanup?.()\n\ttarget.atoms.delete(key)\n\ttarget.valueMap.delete(key)\n\tconst selectorKeys = target.selectorAtoms.getRelatedKeys(key)\n\tif (selectorKeys) {\n\t\tfor (const selectorKey of selectorKeys) {\n\t\t\tconst token =\n\t\t\t\ttarget.selectors.get(selectorKey) ??\n\t\t\t\ttarget.readonlySelectors.get(selectorKey)\n\t\t\tif (token) {\n\t\t\t\tdeleteSelector(token, store)\n\t\t\t}\n\t\t}\n\t}\n\ttarget.selectorAtoms.delete(key)\n\ttarget.atomsThatAreDefault.delete(key)\n\ttarget.timelineAtoms.delete(key)\n\tstore.logger.info(`๐Ÿ”ฅ`, `atom`, `${key}`, `deleted`)\n}\n","import type { Store } from \"./store\"\n\nexport type EnvironmentData = {\n\truntime: `browser` | `node` | `unknown`\n\tstore: Store\n}\n\nexport function getEnvironmentData(store: Store): EnvironmentData {\n\treturn {\n\t\truntime:\n\t\t\ttypeof window === `undefined`\n\t\t\t\t? typeof global === `object`\n\t\t\t\t\t? `node`\n\t\t\t\t\t: `unknown`\n\t\t\t\t: `browser`,\n\t\tstore,\n\t}\n}\n","import type { KeyedStateUpdate } from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport type { Store } from \"../store\"\n\nexport function ingestAtomUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tatomUpdate: KeyedStateUpdate<any>,\n\tstore: Store,\n): void {\n\tconst { key, newValue, oldValue } = atomUpdate\n\tconst value = applying === `newValue` ? newValue : oldValue\n\tsetState({ key, type: `atom` }, value, store)\n}\n","import type { Store } from \"../store\"\nimport type { TimelineSelectorUpdate } from \"../timeline\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\n\nexport function ingestSelectorUpdate(\n\tapplying: `newValue` | `oldValue`,\n\tselectorUpdate: TimelineSelectorUpdate<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? selectorUpdate.atomUpdates\n\t\t\t: [...selectorUpdate.atomUpdates].reverse()\n\tfor (const atomUpdate of updates) {\n\t\tingestAtomUpdate(applying, atomUpdate, store)\n\t}\n}\n","import type { TransactionUpdate } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { ingestAtomUpdate } from \"./ingest-atom-update\"\n\nexport function ingestTransactionUpdate(\n\tapplying: `newValue` | `oldValue`,\n\ttransactionUpdate: TransactionUpdate<any>,\n\tstore: Store,\n): void {\n\tconst updates =\n\t\tapplying === `newValue`\n\t\t\t? transactionUpdate.updates\n\t\t\t: [...transactionUpdate.updates].reverse()\n\tfor (const updateFromTransaction of updates) {\n\t\tif (`newValue` in updateFromTransaction) {\n\t\t\tingestAtomUpdate(applying, updateFromTransaction, store)\n\t\t} else {\n\t\t\tingestTransactionUpdate(applying, updateFromTransaction, store)\n\t\t}\n\t}\n}\n","export class LazyMap<K, V> extends Map<K, V> {\n\tpublic deleted = new Set<K>()\n\n\tpublic constructor(protected readonly source: Map<K, V>) {\n\t\tsuper()\n\t}\n\n\tpublic get(key: K): V | undefined {\n\t\tconst has = super.has(key)\n\t\tif (has) {\n\t\t\treturn super.get(key)\n\t\t}\n\t\tif (!this.deleted.has(key) && this.source.has(key)) {\n\t\t\tconst value = this.source.get(key)\n\t\t\treturn value\n\t\t}\n\t\treturn undefined\n\t}\n\n\tpublic set(key: K, value: V): this {\n\t\tthis.deleted.delete(key)\n\t\treturn super.set(key, value)\n\t}\n\n\tpublic hasOwn(key: K): boolean {\n\t\treturn super.has(key)\n\t}\n\n\tpublic has(key: K): boolean {\n\t\treturn !this.deleted.has(key) && (super.has(key) || this.source.has(key))\n\t}\n\n\tpublic delete(key: K): boolean {\n\t\tthis.deleted.add(key)\n\t\treturn super.delete(key)\n\t}\n}\n","import type { ReadableToken } from \"atom.io\"\n\nimport type { Store } from \"./store\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nfunction prettyPrintTokenType(token: ReadableToken<any>) {\n\tif (token.type === `readonly_selector`) {\n\t\treturn `Readonly Selector`\n\t}\n\treturn capitalize(token.type)\n}\n\nexport class NotFoundError extends Error {\n\tpublic constructor(token: ReadableToken<any>, store: Store) {\n\t\tsuper(\n\t\t\t`${prettyPrintTokenType(token)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import type { AtomToken, TransactionUpdate, ฦ’n } from \"atom.io\"\nimport type { TimelineUpdate } from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { getUpdateToken } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineTransactionUpdate,\n} from \"./create-timeline\"\n\nexport const addAtomToTimeline = (\n\tatomToken: AtomToken<any>,\n\ttl: Timeline<any>,\n\tstore: Store,\n): void => {\n\tlet maybeAtom = withdraw(atomToken, store)\n\tif (maybeAtom?.type === `mutable_atom`) {\n\t\tconst updateToken = getUpdateToken(maybeAtom)\n\t\tmaybeAtom = withdraw(updateToken, store)\n\t}\n\tconst atom = maybeAtom\n\tif (atom === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to atom \"${atomToken.key}\" because it has not been initialized in store \"${store.config.name}\"`,\n\t\t)\n\t}\n\tstore.timelineAtoms.set({ atomKey: atom.key, timelineKey: tl.key })\n\n\tatom.subject.subscribe(`timeline`, (update) => {\n\t\t// debugger\n\t\tconst target = newest(store)\n\t\tconst currentSelectorKey =\n\t\t\tstore.operation.open && store.operation.token.type === `selector`\n\t\t\t\t? store.operation.token.key\n\t\t\t\t: null\n\t\tconst currentSelectorTime =\n\t\t\tstore.operation.open && store.operation.token.type === `selector`\n\t\t\t\t? store.operation.time\n\t\t\t\t: null\n\t\tconst currentTransactionKey = target.on.transactionApplying.state?.update.key\n\t\tconst currentTransactionTime = target.on.transactionApplying.state?.time\n\n\t\tstore.logger.info(\n\t\t\t`โณ`,\n\t\t\t`timeline`,\n\t\t\ttl.key,\n\t\t\t`atom`,\n\t\t\tatomToken.key,\n\t\t\t`went`,\n\t\t\tupdate.oldValue,\n\t\t\t`->`,\n\t\t\tupdate.newValue,\n\t\t\tcurrentTransactionKey\n\t\t\t\t? `in transaction \"${currentTransactionKey}\"`\n\t\t\t\t: currentSelectorKey\n\t\t\t\t ? `in selector \"${currentSelectorKey}\"`\n\t\t\t\t : ``,\n\t\t)\n\t\tif (tl.timeTraveling === null) {\n\t\t\tif (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {\n\t\t\t\tconst mostRecentUpdate: TimelineUpdate<any> | undefined =\n\t\t\t\t\ttl.history.at(-1)\n\t\t\t\tif (mostRecentUpdate === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Timeline \"${tl.key}\" has a selectorTime, but no history. This is most likely a bug in AtomIO.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (currentTransactionKey) {\n\t\t\t\tconst currentTransaction = withdraw(\n\t\t\t\t\t{ key: currentTransactionKey, type: `transaction` },\n\t\t\t\t\tstore,\n\t\t\t\t)\n\t\t\t\tif (currentTransaction === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Transaction \"${currentTransactionKey}\" not found in store \"${store.config.name}\". This is surprising, because we are in the application phase of \"${currentTransactionKey}\".`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (tl.transactionKey !== currentTransactionKey) {\n\t\t\t\t\tif (tl.transactionKey) {\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\ttl.key,\n\t\t\t\t\t\t\t`unable to resolve transaction \"${tl.transactionKey}. This is probably a bug in AtomIO.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\ttl.transactionKey = currentTransactionKey\n\t\t\t\t\tconst unsubscribe = currentTransaction.subject.subscribe(\n\t\t\t\t\t\t`timeline:${tl.key}`,\n\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\tif (tl.timeTraveling === null && currentTransactionTime) {\n\t\t\t\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst filterUpdates = (\n\t\t\t\t\t\t\t\t\tupdates: TransactionUpdate<ฦ’n>[`updates`],\n\t\t\t\t\t\t\t\t) =>\n\t\t\t\t\t\t\t\t\tupdates\n\t\t\t\t\t\t\t\t\t\t.filter((updateFromTx) => {\n\t\t\t\t\t\t\t\t\t\t\tconst target = newest(store)\n\t\t\t\t\t\t\t\t\t\t\tif (`updates` in updateFromTx) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn true\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tconst atomOrFamilyKeys =\n\t\t\t\t\t\t\t\t\t\t\t\ttarget.timelineAtoms.getRelatedKeys(tl.key)\n\n\t\t\t\t\t\t\t\t\t\t\treturn atomOrFamilyKeys\n\t\t\t\t\t\t\t\t\t\t\t\t? [...atomOrFamilyKeys].some(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey === updateFromTx.key ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey === updateFromTx.family?.key,\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: false\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t.map((updateFromTx) => {\n\t\t\t\t\t\t\t\t\t\t\tif (`updates` in updateFromTx) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\t...updateFromTx,\n\t\t\t\t\t\t\t\t\t\t\t\t\tupdates: filterUpdates(updateFromTx.updates),\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn updateFromTx\n\t\t\t\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\t\tconst updates = filterUpdates(update.updates)\n\n\t\t\t\t\t\t\t\tconst timelineTransactionUpdate: TimelineTransactionUpdate = {\n\t\t\t\t\t\t\t\t\ttype: `transaction_update`,\n\t\t\t\t\t\t\t\t\ttimestamp: currentTransactionTime,\n\t\t\t\t\t\t\t\t\t...update,\n\t\t\t\t\t\t\t\t\tupdates,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst willCapture =\n\t\t\t\t\t\t\t\t\ttl.shouldCapture?.(timelineTransactionUpdate, tl) ?? true\n\t\t\t\t\t\t\t\tif (willCapture) {\n\t\t\t\t\t\t\t\t\ttl.history.push(timelineTransactionUpdate)\n\t\t\t\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\t\t\t\ttl.subject.next(timelineTransactionUpdate)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttl.transactionKey = null\n\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t`โŒ›`,\n\t\t\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t\t`got a transaction_update \"${update.key}\"`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (currentSelectorKey && currentSelectorTime) {\n\t\t\t\tlet latestUpdate: TimelineUpdate<any> | undefined = tl.history.at(-1)\n\n\t\t\t\tif (currentSelectorTime !== tl.selectorTime) {\n\t\t\t\t\tlatestUpdate = {\n\t\t\t\t\t\ttype: `selector_update`,\n\t\t\t\t\t\ttimestamp: currentSelectorTime,\n\t\t\t\t\t\tkey: currentSelectorKey,\n\t\t\t\t\t\tatomUpdates: [],\n\t\t\t\t\t}\n\t\t\t\t\tlatestUpdate.atomUpdates.push({\n\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t...update,\n\t\t\t\t\t})\n\t\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t\t}\n\n\t\t\t\t\ttl.history.push(latestUpdate)\n\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`โŒ›`,\n\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t`got a selector_update \"${currentSelectorKey}\" with`,\n\t\t\t\t\t\tlatestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),\n\t\t\t\t\t)\n\n\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\ttl.selectorTime = currentSelectorTime\n\t\t\t\t} else {\n\t\t\t\t\tif (latestUpdate?.type === `selector_update`) {\n\t\t\t\t\t\tlatestUpdate.atomUpdates.push({\n\t\t\t\t\t\t\tkey: atom.key,\n\t\t\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\t\t\t...update,\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`set selector_update \"${currentSelectorKey}\" to`,\n\t\t\t\t\t\t\tlatestUpdate?.atomUpdates.map((atomUpdate) => atomUpdate.key),\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (latestUpdate) {\n\t\t\t\t\tconst willCaptureSelectorUpdate =\n\t\t\t\t\t\ttl.shouldCapture?.(latestUpdate, tl) ?? true\n\t\t\t\t\tif (willCaptureSelectorUpdate) {\n\t\t\t\t\t\ttl.subject.next(latestUpdate)\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttl.history.pop()\n\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst timestamp = Date.now()\n\t\t\t\ttl.selectorTime = null\n\t\t\t\tif (tl.at !== tl.history.length) {\n\t\t\t\t\ttl.history.splice(tl.at)\n\t\t\t\t}\n\t\t\t\tconst atomUpdate: TimelineAtomUpdate<any> = {\n\t\t\t\t\ttype: `atom_update`,\n\t\t\t\t\ttimestamp,\n\t\t\t\t\tkey: atom.key,\n\t\t\t\t\toldValue: update.oldValue,\n\t\t\t\t\tnewValue: update.newValue,\n\t\t\t\t}\n\t\t\t\tif (atom.family) {\n\t\t\t\t\tatomUpdate.family = atom.family\n\t\t\t\t}\n\t\t\t\tconst willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true\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`got an atom_update to \"${atom.key}\"`,\n\t\t\t\t)\n\t\t\t\tif (willCapture) {\n\t\t\t\t\ttl.history.push(atomUpdate)\n\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\ttl.subject.next(atomUpdate)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t})\n}\n","import type {\n\tAtomFamily,\n\tFamilyMetadata,\n\tStateUpdate,\n\tTimelineManageable,\n\tTimelineOptions,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTokenType,\n\tTransactionUpdate,\n\tฦ’n,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { getUpdateToken, isMutable } from \"../mutable\"\nimport { type Store, withdraw } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { addAtomToTimeline } from \"./add-atom-to-timeline\"\n\nexport type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> =\n\tStateUpdate<TokenType<ManagedAtom>> & {\n\t\tkey: string\n\t\ttype: `atom_update`\n\t\ttimestamp: number\n\t\tfamily?: FamilyMetadata\n\t}\nexport type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\ttype: `selector_update`\n\ttimestamp: number\n\tatomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[]\n}\nexport type TimelineTransactionUpdate = TransactionUpdate<ฦ’n> & {\n\tkey: string\n\ttype: `transaction_update`\n\ttimestamp: number\n}\n\nexport type Timeline<ManagedAtom extends TimelineManageable> = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<TimelineManageable>,\n\t\ttimeline: Timeline<ManagedAtom>,\n\t) => boolean\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineUpdate<ManagedAtom>[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: Store) => void\n\tsubject: Subject<\n\t\t| TimelineAtomUpdate<ManagedAtom>\n\t\t| TimelineSelectorUpdate<ManagedAtom>\n\t\t| TimelineTransactionUpdate\n\t\t| `redo`\n\t\t| `undo`\n\t>\n}\n\nexport function createTimeline<ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n\tstore: Store,\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: (store) => createTimeline(options, store, tl),\n\t\tsubject: new Subject(),\n\t}\n\tif (options.shouldCapture) {\n\t\ttl.shouldCapture = options.shouldCapture\n\t}\n\tconst timelineKey = options.key\n\tconst target = newest(store)\n\tfor (const tokenOrFamily of options.atoms) {\n\t\tlet atomKey = tokenOrFamily.key\n\t\tif (\n\t\t\ttokenOrFamily.type === `atom_family` ||\n\t\t\ttokenOrFamily.type === `mutable_atom_family`\n\t\t) {\n\t\t\tconst family: AtomFamily<any> = tokenOrFamily\n\t\t\tconst familyKey = family.key\n\t\t\ttarget.timelineAtoms.set({ atomKey: familyKey, timelineKey })\n\t\t\tfamily.subject.subscribe(`timeline:${options.key}`, (token) => {\n\t\t\t\taddAtomToTimeline(token, tl, store)\n\t\t\t})\n\t\t\tfor (const atom of target.atoms.values()) {\n\t\t\t\tif (atom.family?.key === familyKey) {\n\t\t\t\t\taddAtomToTimeline(atom, tl, store)\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tlet atom = withdraw(tokenOrFamily, store)\n\t\t\tif (atom === undefined) {\n\t\t\t\tstore.logger.error(\n\t\t\t\t\t`โŒ`,\n\t\t\t\t\t`timeline`,\n\t\t\t\t\toptions.key,\n\t\t\t\t\t`Failed to add atom \"${atomKey}\" because it does not exist in the store`,\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (isMutable(atom)) {\n\t\t\t\tconst updateAtom = withdraw(getUpdateToken(atom), store)\n\t\t\t\tif (updateAtom === undefined) {\n\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t`โŒ`,\n\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t`Failed to add update atom \"${atomKey}\" because it does not exist in the store`,\n\t\t\t\t\t)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tatom = updateAtom\n\t\t\t\tatomKey = atom.key\n\t\t\t}\n\t\t\tif (`family` in atom) {\n\t\t\t\tconst familyTimelineKey = target.timelineAtoms.getRelatedKey(\n\t\t\t\t\tatom.family.key,\n\t\t\t\t)\n\t\t\t\tif (familyTimelineKey) {\n\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t`โŒ`,\n\t\t\t\t\t\t`timeline`,\n\t\t\t\t\t\toptions.key,\n\t\t\t\t\t\t`Failed to add atom \"${atom.key}\" because its family \"${atom.family.key}\" already belongs to timeline \"${familyTimelineKey}\"`,\n\t\t\t\t\t)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst existingTimelineKey = target.timelineAtoms.getRelatedKey(atomKey)\n\t\t\tif (existingTimelineKey) {\n\t\t\t\tstore.logger.error(\n\t\t\t\t\t`โŒ`,\n\t\t\t\t\t`timeline`,\n\t\t\t\t\toptions.key,\n\t\t\t\t\t`Failed to add atom \"${atomKey}\" because it already belongs to timeline \"${existingTimelineKey}\"`,\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\taddAtomToTimeline(atom, tl, store)\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","import type { TimelineToken } from \"atom.io\"\n\nimport {\n\tingestAtomUpdate,\n\tingestSelectorUpdate,\n\tingestTransactionUpdate,\n} from \"../ingest-updates\"\nimport type { Store } from \"../store\"\n\nexport const timeTravel = (\n\taction: `redo` | `undo`,\n\ttoken: TimelineToken<any>,\n\tstore: Store,\n): void => {\n\tstore.logger.info(\n\t\taction === `redo` ? `โฉ` : `โช`,\n\t\t`timeline`,\n\t\ttoken.key,\n\t\taction,\n\t)\n\tconst timelineData = store.timelines.get(token.key)\n\tif (!timelineData) {\n\t\tstore.logger.error(\n\t\t\t`๐Ÿž`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Failed to ${action}. This timeline has not been initialized.`,\n\t\t)\n\t\treturn\n\t}\n\tif (\n\t\t(action === `redo` && timelineData.at === timelineData.history.length) ||\n\t\t(action === `undo` && timelineData.at === 0)\n\t) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿ’`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Failed to ${action} at the ${\n\t\t\t\taction === `redo` ? `end` : `beginning`\n\t\t\t} of timeline \"${token.key}\". There is nothing to ${action}.`,\n\t\t)\n\t\treturn\n\t}\n\n\ttimelineData.timeTraveling = action === `redo` ? `into_future` : `into_past`\n\tif (action === `undo`) {\n\t\t--timelineData.at\n\t}\n\n\tconst update = timelineData.history[timelineData.at]\n\tconst applying = action === `redo` ? `newValue` : `oldValue`\n\n\tswitch (update.type) {\n\t\tcase `atom_update`: {\n\t\t\tingestAtomUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `selector_update`: {\n\t\t\tingestSelectorUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `transaction_update`: {\n\t\t\tingestTransactionUpdate(applying, update, store)\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif (action === `redo`) {\n\t\t++timelineData.at\n\t}\n\n\ttimelineData.subject.next(action)\n\ttimelineData.timeTraveling = null\n\tstore.logger.info(\n\t\t`โน๏ธ`,\n\t\t`timeline`,\n\t\ttoken.key,\n\t\t`\"${token.key}\" is now at ${timelineData.at} / ${timelineData.history.length}`,\n\t)\n}\n","import { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const abortTransaction = (store: Store): void => {\n\tconst target = newest(store)\n\tif (target.transactionMeta === null || target.parent === null) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿž`,\n\t\t\t`transaction`,\n\t\t\t`???`,\n\t\t\t`abortTransaction called outside of a transaction. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.logger.info(\n\t\t`๐Ÿช‚`,\n\t\t`transaction`,\n\t\ttarget.transactionMeta.update.key,\n\t\t`Aborting transaction`,\n\t)\n\ttarget.parent.child = null\n}\n","import type { ฦ’n } from \"atom.io\"\n\nimport { ingestTransactionUpdate } from \"../ingest-updates\"\nimport { newest } from \"../lineage\"\nimport { withdraw } from \"../store\"\nimport type { Store } from \"../store\"\n\nexport const applyTransaction = <ฦ’ extends ฦ’n>(\n\toutput: ReturnType<ฦ’>,\n\tstore: Store,\n): void => {\n\tconst child = newest(store)\n\tconst { parent } = child\n\tif (\n\t\tparent === null ||\n\t\tchild.transactionMeta === null ||\n\t\tchild.transactionMeta?.phase !== `building`\n\t) {\n\t\tstore.logger.warn(\n\t\t\t`๐Ÿž`,\n\t\t\t`transaction`,\n\t\t\t`???`,\n\t\t\t`applyTransaction called outside of a transaction. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tchild.transactionMeta.phase = `applying`\n\tchild.transactionMeta.update.output = output\n\tparent.child = null\n\tparent.on.transactionApplying.next(child.transactionMeta)\n\tconst { updates } = child.transactionMeta.update\n\tstore.logger.info(\n\t\t`๐Ÿ›„`,\n\t\t`transaction`,\n\t\tchild.transactionMeta.update.key,\n\t\t`Applying transaction with ${updates.length} updates:`,\n\t\tupdates,\n\t)\n\tfor (const tracker of child.trackers.values()) {\n\t\tconst mutableKey = tracker.mutableState.key\n\t\tif (!parent.atoms.has(mutableKey)) {\n\t\t\tconst atom = child.atoms.get(mutableKey)\n\t\t\tatom?.install(parent)\n\t\t}\n\t\ttracker.dispose()\n\t}\n\tfor (const atom of child.atoms.values()) {\n\t\tif (!parent.atoms.has(atom.key)) {\n\t\t\tparent.atoms.set(atom.key, atom)\n\t\t\tparent.valueMap.set(atom.key, atom.default)\n\t\t\tparent.logger.info(\n\t\t\t\t`๐Ÿ”จ`,\n\t\t\t\t`transaction`,\n\t\t\t\tchild.transactionMeta.update.key,\n\t\t\t\t`Adding atom \"${atom.key}\"`,\n\t\t\t)\n\t\t}\n\t}\n\tingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent)\n\tif (parent.transactionMeta === null) {\n\t\tconst myTransaction = withdraw<ฦ’>(\n\t\t\t{ key: child.transactionMeta.update.key, type: `transaction` },\n\t\t\tstore,\n\t\t)\n\t\tmyTransaction?.subject.next(child.transactionMeta.update)\n\t\tstore.logger.info(\n\t\t\t`๐Ÿ›ฌ`,\n\t\t\t`transaction`,\n\t\t\tchild.transactionMeta.update.key,\n\t\t\t`Finished applying transaction.`,\n\t\t)\n\t} else {\n\t\tparent.transactionMeta.update.updates.push(child.transactionMeta.update)\n\t}\n\tparent.on.transactionApplying.next(null)\n}\n","import { findInStore, getState, runTransaction, setState } from \"atom.io\"\nimport type { findState } from \"atom.io\"\n\nimport { Junction } from \"~/packages/rel8/junction/src\"\n\nimport { getEnvironmentData } from \"../get-environment-data\"\nimport { LazyMap } from \"../lazy-map\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport const buildTransaction = (\n\tkey: string,\n\tparams: any[],\n\tstore: Store,\n\tid?: string,\n): void => {\n\tconst parent = newest(store)\n\tconst child: Store = {\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\ttransactionMeta: null,\n\t\tatoms: new LazyMap(parent.atoms),\n\t\tatomsThatAreDefault: new Set(parent.atomsThatAreDefault),\n\t\tfamilies: new LazyMap(parent.families),\n\t\toperation: { open: false },\n\t\treadonlySelectors: new LazyMap(parent.readonlySelectors),\n\t\ttimelines: new LazyMap(parent.timelines),\n\t\ttimelineAtoms: new Junction(parent.timelineAtoms.toJSON()),\n\t\ttrackers: new Map(),\n\t\ttransactions: new LazyMap(parent.transactions),\n\t\tselectorAtoms: new Junction(parent.selectorAtoms.toJSON()),\n\t\tselectorGraph: new Junction(parent.selectorGraph.toJSON(), {\n\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t}),\n\t\tselectors: new LazyMap(parent.selectors),\n\t\tvalueMap: new LazyMap(parent.valueMap),\n\t}\n\tchild.transactionMeta = {\n\t\tphase: `building`,\n\t\ttime: Date.now(),\n\t\tupdate: {\n\t\t\tkey,\n\t\t\tid: id ?? Math.random().toString(36).slice(2),\n\t\t\tupdates: [],\n\t\t\tparams,\n\t\t\toutput: undefined,\n\t\t},\n\t\ttransactors: {\n\t\t\tget: (token) => getState(token, child),\n\t\t\tset: (token, value) => setState(token, value, child),\n\t\t\trun: (token) => runTransaction(token, child),\n\t\t\tfind: ((token, key) => findInStore(token, key, child)) as typeof findState,\n\t\t\tenv: () => getEnvironmentData(child),\n\t\t},\n\t}\n\tparent.child = child\n\tstore.logger.info(\n\t\t`๐Ÿ›ซ`,\n\t\t`transaction`,\n\t\tkey,\n\t\t`Building transaction with params:`,\n\t\tparams,\n\t)\n}\n","import type {\n\tTransactionOptions,\n\tTransactionToken,\n\tTransactionUpdate,\n\tฦ’n,\n} from \"atom.io\"\n\nimport { newest } from \"../lineage\"\nimport { deposit } from \"../store\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { abortTransaction } from \"./abort-transaction\"\nimport { applyTransaction } from \"./apply-transaction\"\nimport { buildTransaction } from \"./build-transaction\"\n\nexport type Transaction<ฦ’ extends ฦ’n> = {\n\tkey: string\n\ttype: `transaction`\n\tinstall: (store: Store) => void\n\tsubject: Subject<TransactionUpdate<ฦ’>>\n\trun: (parameters: Parameters<ฦ’>, id?: string) => ReturnType<ฦ’>\n}\n\nexport function createTransaction<ฦ’ extends ฦ’n>(\n\toptions: TransactionOptions<ฦ’>,\n\tstore: Store,\n): TransactionToken<ฦ’> {\n\tconst newTransaction: Transaction<ฦ’> = {\n\t\tkey: options.key,\n\t\ttype: `transaction`,\n\t\trun: (params: Parameters<ฦ’>, id?: string) => {\n\t\t\tbuildTransaction(options.key, params, store, id)\n\t\t\ttry {\n\t\t\t\tconst target = newest(store)\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: this happens right above\n\t\t\t\tconst { transactors } = target.transactionMeta!\n\t\t\t\tconst output = options.do(transactors, ...params)\n\t\t\t\tapplyTransaction(output, target)\n\t\t\t\treturn output\n\t\t\t} catch (thrown) {\n\t\t\t\tabortTransaction(target)\n\t\t\t\tstore.logger.warn(`๐Ÿ’ฅ`, `transaction`, options.key, `caught:`, thrown)\n\t\t\t\tthrow thrown\n\t\t\t}\n\t\t},\n\t\tinstall: (store) => createTransaction(options, store),\n\t\tsubject: new Subject(),\n\t}\n\tconst target = newest(store)\n\ttarget.transactions.set(newTransaction.key, newTransaction)\n\tconst token = deposit(newTransaction)\n\tstore.on.transactionCreation.next(token)\n\treturn token\n}\n","import type { TransactionUpdate, TransactorsWithRunAndEnv, ฦ’n } from \"atom.io\"\n\nexport * from \"./abort-transaction\"\nexport * from \"./apply-transaction\"\nexport * from \"./build-transaction\"\nexport * from \"./create-transaction\"\n\nexport const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const\nexport type TransactionPhase = (typeof TRANSACTION_PHASES)[number]\n\nexport type TransactionMeta<ฦ’ extends ฦ’n> = {\n\tphase: `applying` | `building`\n\ttime: number\n\tupdate: TransactionUpdate<ฦ’>\n\ttransactors: TransactorsWithRunAndEnv\n}\n"]}