atom.io 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/dist/index.cjs +614 -0
- package/data/dist/index.cjs.map +1 -0
- package/data/dist/index.d.cts +158 -0
- package/data/dist/index.d.ts +118 -1
- package/data/dist/index.js +551 -30
- package/data/dist/index.js.map +1 -1
- package/data/dist/metafile-cjs.json +1 -0
- package/data/dist/metafile-esm.json +1 -0
- package/data/package.json +4 -3
- package/data/src/index.ts +1 -0
- package/data/src/join.ts +450 -0
- package/data/src/struct-family.ts +34 -24
- package/data/src/struct.ts +6 -8
- package/dist/index.cjs +257 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +10 -11
- package/dist/index.d.ts +10 -11
- package/dist/index.js +63 -104
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/internal/dist/{index.mjs → index.cjs} +692 -503
- package/internal/dist/index.cjs.map +1 -0
- package/internal/dist/{index.d.mts → index.d.cts} +114 -105
- package/internal/dist/index.d.ts +114 -105
- package/internal/dist/index.js +628 -563
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/metafile-cjs.json +1 -0
- package/internal/dist/metafile-esm.json +1 -0
- package/internal/package.json +4 -3
- package/internal/src/atom/create-atom.ts +29 -16
- package/internal/src/atom/delete-atom.ts +25 -6
- package/internal/src/atom/is-default.ts +4 -17
- package/internal/src/caching.ts +28 -23
- package/internal/src/families/create-atom-family.ts +3 -2
- package/internal/src/families/create-readonly-selector-family.ts +1 -1
- package/internal/src/families/create-selector-family.ts +4 -4
- package/internal/src/index.ts +2 -1
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
- package/internal/src/mutable/create-mutable-atom.ts +1 -2
- package/internal/src/mutable/get-json-family.ts +22 -0
- package/internal/src/mutable/get-json-token.ts +1 -0
- package/internal/src/mutable/index.ts +1 -0
- package/internal/src/mutable/tracker-family.ts +1 -2
- package/internal/src/mutable/tracker.ts +8 -6
- package/internal/src/mutable/transceiver.ts +2 -0
- package/internal/src/not-found-error.ts +27 -0
- package/internal/src/operation.ts +2 -3
- package/internal/src/{get-state-internal.ts → read-or-compute-value.ts} +13 -6
- package/internal/src/selector/create-selector.ts +6 -7
- package/internal/src/selector/delete-selector.ts +37 -0
- package/internal/src/selector/index.ts +2 -1
- package/internal/src/selector/register-selector.ts +7 -7
- package/internal/src/set-state/copy-mutable-in-transaction.ts +3 -2
- package/internal/src/set-state/emit-update.ts +1 -3
- package/internal/src/set-state/evict-downstream.ts +6 -8
- package/internal/src/set-state/index.ts +1 -1
- package/internal/src/set-state/{set-state-internal.ts → set-atom-or-selector.ts} +2 -3
- package/internal/src/set-state/set-atom.ts +5 -6
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw-new-family-member.ts +6 -6
- package/internal/src/subscribe/recall-state.ts +1 -2
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +2 -2
- package/internal/src/timeline/add-atom-to-timeline.ts +5 -16
- package/internal/src/timeline/{timeline-internal.ts → create-timeline.ts} +4 -5
- package/internal/src/timeline/index.ts +2 -2
- package/internal/src/timeline/time-travel.ts +89 -0
- package/internal/src/transaction/{transaction-internal.ts → create-transaction.ts} +6 -5
- package/internal/src/transaction/index.ts +2 -3
- package/introspection/dist/{index.mjs → index.cjs} +54 -29
- package/introspection/dist/index.cjs.map +1 -0
- package/introspection/dist/{index.d.mts → index.d.cts} +2 -2
- package/introspection/dist/index.d.ts +2 -2
- package/introspection/dist/index.js +32 -49
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/metafile-cjs.json +1 -0
- package/introspection/dist/metafile-esm.json +1 -0
- package/introspection/package.json +4 -3
- package/introspection/src/attach-introspection-states.ts +2 -2
- package/introspection/src/attach-selector-index.ts +8 -4
- package/json/dist/{index.mjs → index.cjs} +20 -7
- package/json/dist/{index.mjs.map → index.cjs.map} +1 -1
- package/json/dist/{index.d.mts → index.d.cts} +1 -1
- package/json/dist/index.d.ts +1 -1
- package/json/dist/index.js +6 -19
- package/json/dist/index.js.map +1 -1
- package/json/dist/metafile-cjs.json +1 -0
- package/json/dist/metafile-esm.json +1 -0
- package/json/package.json +4 -3
- package/package.json +48 -47
- package/react/dist/index.cjs +59 -0
- package/react/dist/index.cjs.map +1 -0
- package/react/dist/index.js +20 -42
- package/react/dist/index.js.map +1 -1
- package/react/dist/metafile-cjs.json +1 -0
- package/react/dist/metafile-esm.json +1 -0
- package/react/package.json +4 -3
- package/react/src/store-hooks.ts +8 -2
- package/react-devtools/dist/{index.mjs → index.cjs} +286 -240
- package/react-devtools/dist/index.cjs.map +1 -0
- package/react-devtools/dist/{index.d.mts → index.d.cts} +29 -17
- package/react-devtools/dist/index.d.ts +29 -17
- package/react-devtools/dist/index.js +251 -273
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/metafile-cjs.json +1 -0
- package/react-devtools/dist/metafile-esm.json +1 -0
- package/react-devtools/package.json +4 -3
- package/react-devtools/src/StateEditor.tsx +8 -8
- package/realtime-client/dist/{index.mjs → index.cjs} +50 -21
- package/realtime-client/dist/index.js +20 -49
- package/realtime-client/dist/metafile-cjs.json +1 -0
- package/realtime-client/dist/metafile-esm.json +1 -0
- package/realtime-client/package.json +4 -3
- package/realtime-react/dist/index.cjs +99 -0
- package/realtime-react/dist/index.js +35 -66
- package/realtime-react/dist/metafile-cjs.json +1 -0
- package/realtime-react/dist/metafile-esm.json +1 -0
- package/realtime-react/package.json +4 -3
- package/realtime-server/dist/{index.mjs → index.cjs} +67 -40
- package/realtime-server/dist/index.js +39 -66
- package/realtime-server/dist/metafile-cjs.json +1 -0
- package/realtime-server/dist/metafile-esm.json +1 -0
- package/realtime-server/package.json +4 -3
- package/realtime-testing/dist/{index.mjs → index.cjs} +54 -23
- package/realtime-testing/dist/index.js +22 -53
- package/realtime-testing/dist/metafile-cjs.json +1 -0
- package/realtime-testing/dist/metafile-esm.json +1 -0
- package/realtime-testing/package.json +4 -3
- package/src/atom.ts +6 -8
- package/src/dispose.ts +18 -0
- package/src/get-state.ts +16 -0
- package/src/index.ts +3 -1
- package/src/logger.ts +1 -1
- package/src/selector.ts +3 -3
- package/src/set-state.ts +22 -0
- package/src/silo.ts +7 -8
- package/src/timeline.ts +6 -11
- package/src/transaction.ts +2 -2
- package/transceivers/set-rtx/dist/{index.mjs → index.cjs} +40 -36
- package/transceivers/set-rtx/dist/index.cjs.map +1 -0
- package/transceivers/set-rtx/dist/{index.d.mts → index.d.cts} +2 -1
- package/transceivers/set-rtx/dist/index.d.ts +2 -1
- package/transceivers/set-rtx/dist/index.js +37 -37
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/transceivers/set-rtx/dist/metafile-cjs.json +1 -0
- package/transceivers/set-rtx/dist/metafile-esm.json +1 -0
- package/transceivers/set-rtx/package.json +4 -3
- package/transceivers/set-rtx/src/set-rtx.ts +29 -26
- package/data/dist/index.d.mts +0 -41
- package/data/dist/index.mjs +0 -82
- package/data/dist/index.mjs.map +0 -1
- package/dist/index.mjs +0 -215
- package/dist/index.mjs.map +0 -1
- package/internal/dist/index.mjs.map +0 -1
- package/internal/src/set-state/set-selector-state.ts +0 -8
- package/internal/src/timeline/time-travel-internal.ts +0 -109
- package/introspection/dist/index.mjs.map +0 -1
- package/react/dist/index.mjs +0 -29
- package/react/dist/index.mjs.map +0 -1
- package/react-devtools/dist/index.mjs.map +0 -1
- package/realtime-react/dist/index.mjs +0 -68
- package/src/get-set.ts +0 -48
- package/transceivers/set-rtx/dist/index.mjs.map +0 -1
- /package/react/dist/{index.d.mts → index.d.cts} +0 -0
- /package/realtime-client/dist/{index.mjs.map → index.cjs.map} +0 -0
- /package/realtime-client/dist/{index.d.mts → index.d.cts} +0 -0
- /package/realtime-react/dist/{index.mjs.map → index.cjs.map} +0 -0
- /package/realtime-react/dist/{index.d.mts → index.d.cts} +0 -0
- /package/realtime-server/dist/{index.mjs.map → index.cjs.map} +0 -0
- /package/realtime-server/dist/{index.d.mts → index.d.cts} +0 -0
- /package/realtime-testing/dist/{index.mjs.map → index.cjs.map} +0 -0
- /package/realtime-testing/dist/{index.d.mts → index.d.cts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atom/create-atom.ts","../src/future.ts","../src/store/deposit.ts","../src/store/store.ts","../../../rel8/junction/src/junction.ts","../src/subject.ts","../src/transaction/transaction-internal.ts","../src/transaction/abort-transaction.ts","../src/transaction/apply-transaction.ts","../src/transaction/build-transaction.ts","../src/transaction/redo-transaction.ts","../src/transaction/undo-transaction.ts","../src/transaction/index.ts","../src/timeline/add-atom-to-timeline.ts","../src/timeline/time-travel-internal.ts","../src/timeline/timeline-internal.ts","../src/store/withdraw.ts","../src/store/withdraw-new-family-member.ts","../src/caching.ts","../src/mutable/create-mutable-atom.ts","../src/mutable/tracker.ts","../src/mutable/create-mutable-atom-family.ts","../src/mutable/tracker-family.ts","../src/families/create-atom-family.ts","../src/families/create-readonly-selector-family.ts","../src/keys.ts","../src/selector/get-selector-dependency-keys.ts","../src/get-state-internal.ts","../src/set-state/become.ts","../src/operation.ts","../src/set-state/copy-mutable-if-needed.ts","../src/set-state/copy-mutable-in-transaction.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-state-internal.ts","../src/selector/trace-selector-atoms.ts","../src/selector/update-selector-atoms.ts","../src/selector/register-selector.ts","../src/selector/create-read-write-selector.ts","../src/selector/create-readonly-selector.ts","../src/selector/create-selector.ts","../src/families/create-selector-family.ts","../src/mutable/get-json-token.ts","../src/mutable/get-update-token.ts","../src/mutable/is-atom-token-mutable.ts","../src/mutable/transceiver.ts","../src/mutable/index.ts","../src/atom/is-default.ts","../src/atom/delete-atom.ts","../src/subscribe/recall-state.ts","../src/subscribe/subscribe-to-root-atoms.ts"],"names":["setState","subscribe","a","b","token","store","update","_a","_b","value","getState","unsubscribe","stringif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AAK,QAAQ;AAAA,MACnB,GAAG,MAAM,IAAI,IAAI,MAAM,GAAG;AAAA,MAC1B,CAAC,eAAe;AACf,cAAM,OAAO;AAAA,UACZ;AAAA,UACA,MAAM;AAAA,UACN,MAAM;AAAA,UACN;AAAA,UACA;AAAA,UACA;AAAA,UACA,WAAW;AAAA,UACX;AAAA,UACA,WAAW;AAAA,QACZ;AACA,cAAM,WAAW,YAAY,OAAO,KAAK;AAEzC,cAAM,WAAW,mBAAmB,OAAO,KAAK;AAChD,cAAM,OAAO;AAAA,UACZ;AAAA,UACA,MAAM;AAAA,UACN,MAAM;AAAA,UACN;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACD;AACA,cAAM,QAAQ,KAAK,EAAE,UAAU,SAAS,CAAC;AAAA,MAC1C;AAAA,IACD;AAAA,EACA,CAAC;AACL,SAAO;AACR","sourcesContent":["import type {\n\tAtomOptions,\n\tAtomToken,\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tUpdateHandler,\n} from \"atom.io\"\nimport { setState, subscribe } from \"atom.io\"\n\nimport { cacheValue } from \"../caching\"\nimport { createMutableAtom } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT, deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\nimport { markAtomAsDefault } from \"./is-default\"\n\nexport type Atom<T> = {\n\tkey: string\n\ttype: `atom`\n\tfamily?: FamilyMetadata\n\tinstall: (store: Store) => void\n\tsubject: Subject<{ newValue: T; oldValue: T }>\n\tdefault: T\n}\n\nexport function createAtom<T>(\n\toptions: AtomOptions<T> | MutableAtomOptions<any, any>,\n\tfamily?: FamilyMetadata,\n\tstore: Store = IMPLICIT.STORE,\n): AtomToken<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 core = target(store)\n\tconst existing = core.atoms.get(options.key)\n\tif (existing) {\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\t`(Ignore if you are in development using hot module replacement.)`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom = {\n\t\t...options,\n\t\ttype: `atom`,\n\t\tinstall: (store: Store) => {\n\t\t\t// store.logger.info(\n\t\t\t// \t`🛠️ installing atom \"${options.key}\" in store \"${store.config.name}\"`,\n\t\t\t// )\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 `mutable` in options\n\t\t\t\t? createMutableAtom(options, store)\n\t\t\t\t: createAtom(options, undefined, store)\n\t\t},\n\t\tsubject,\n\t\t...(family && { family }),\n\t} as const\n\tconst initialValue =\n\t\toptions.default instanceof Function ? options.default() : options.default\n\tcore.atoms.set(newAtom.key, newAtom)\n\tmarkAtomAsDefault(options.key, store)\n\tcacheValue(options.key, initialValue, subject, store)\n\tconst token = deposit(newAtom)\n\tfor (const effect of options.effects ?? []) {\n\t\teffect({\n\t\t\tsetSelf: (next) => setState(token, next, store),\n\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\tsubscribe(token, handle, `effect[${subject.subscribers.size}]`, store),\n\t\t})\n\t}\n\tstore.subject.atomCreation.next(token)\n\treturn token as AtomToken<T>\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 {\n\tAtomToken,\n\tReadonlySelectorToken,\n\tSelectorToken,\n\tStateToken,\n\tTransactionToken,\n\tƒn,\n} from \"atom.io\"\n\nimport type { Atom } from \"../atom\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport type { Transaction } from \"../transaction\"\n\nexport function deposit<T>(state: Atom<T>): AtomToken<T>\nexport function deposit<T>(state: Selector<T>): SelectorToken<T>\nexport function deposit<T>(state: Atom<T> | Selector<T>): StateToken<T>\nexport function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>\nexport function deposit<T>(\n\tstate: Transaction<T extends ƒn ? T : never>,\n): TransactionToken<T>\nexport function deposit<T>(\n\tstate: Atom<T> | ReadonlySelector<T> | Selector<T>,\n): ReadonlySelectorToken<T> | StateToken<T>\nexport function deposit<T>(\n\tstate:\n\t\t| Atom<T>\n\t\t| ReadonlySelector<T>\n\t\t| Selector<T>\n\t\t| Transaction<T extends ƒn ? T : never>,\n):\n\t| AtomToken<T>\n\t| ReadonlySelectorToken<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, simpleLogger } from \"atom.io\"\nimport type {\n\tAtomFamily,\n\tAtomToken,\n\tLogger,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tSelectorFamily,\n\tSelectorToken,\n\tTimelineToken,\n\tTransactionToken,\n\tƒn,\n} from \"atom.io\"\n\nimport { Junction } from \"~/packages/rel8/junction/src\"\n\nimport type { Atom } from \"../atom\"\nimport type { MutableAtom, Tracker, Transceiver } from \"../mutable\"\nimport type { OperationProgress } from \"../operation\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport { Subject } from \"../subject\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction, TransactionStatus } from \"../transaction\"\n\nexport type StoreCore = Pick<\n\tStore,\n\t| `atoms`\n\t| `atomsThatAreDefault`\n\t| `families`\n\t| `operation`\n\t| `readonlySelectors`\n\t| `selectorAtoms`\n\t| `selectorGraph`\n\t| `selectors`\n\t| `timelineAtoms`\n\t| `timelines`\n\t| `trackers`\n\t| `transactions`\n\t| `valueMap`\n>\n\nexport class Store {\n\tpublic valueMap = new Map<string, any>()\n\n\tpublic atoms = new Map<string, Atom<any> | MutableAtom<any>>()\n\tpublic selectors = new Map<string, Selector<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| AtomFamily<any, any>\n\t\t| ReadonlySelectorFamily<any, any>\n\t\t| SelectorFamily<any, any>\n\t>()\n\n\tpublic timelines = new Map<string, Timeline>()\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 subject = {\n\t\tatomCreation: new Subject<AtomToken<unknown>>(),\n\t\tselectorCreation: new Subject<\n\t\t\tReadonlySelectorToken<unknown> | SelectorToken<unknown>\n\t\t>(),\n\t\ttransactionCreation: new Subject<TransactionToken<ƒn>>(),\n\t\ttimelineCreation: new Subject<TimelineToken>(),\n\t\toperationStatus: new Subject<OperationProgress>(),\n\t}\n\tpublic operation: OperationProgress = { open: false }\n\tpublic transactionStatus: TransactionStatus<ƒn> = { phase: `idle` }\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.transactionStatus = { ...store?.transactionStatus }\n\t\t\tthis.config = {\n\t\t\t\t...store?.config,\n\t\t\t\tname,\n\t\t\t}\n\n\t\t\tfor (const [, atom] of store.atoms) {\n\t\t\t\tatom.install(this)\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\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 = IMPLICIT.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 JunctionAdvancedConfiguration<Content extends Json.Object | null> = {\n\texternalStore?: (Content extends null\n\t\t? {\n\t\t\t\tgetContent?: undefined\n\t\t\t\tsetContent?: undefined\n\t\t\t\tdeleteContent?: undefined\n\t\t }\n\t\t: {\n\t\t\t\tgetContent: (contentKey: string) => Content | undefined\n\t\t\t\tsetContent: (contentKey: string, content: Content) => void\n\t\t\t\tdeleteContent: (contentKey: string) => void\n\t\t }) & {\n\t\taddRelation: (a: string, b: string) => void\n\t\tdeleteRelation: (a: string, b: string) => void\n\t\tgetRelatedKeys: (key: string) => Set<string> | undefined\n\t\thas: (a: string, b?: string) => boolean\n\t}\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\tASide extends string,\n\tBSide extends string,\n\tContent 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\tconst aRelations = this.relations.get(a)\n\t\tconst bRelations = this.relations.get(b)\n\t\tif (aRelations) {\n\t\t\taRelations.add(b)\n\t\t} else {\n\t\t\tthis.relations.set(a, new Set([b]))\n\t\t}\n\t\tif (bRelations) {\n\t\t\tbRelations.add(a)\n\t\t} else {\n\t\t\tthis.relations.set(b, new Set([a]))\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 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\tthis.relations = new Map(data.relations?.map(([a, b]) => [a, new Set(b)]))\n\t\tthis.contents = new Map(data.contents)\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\treturn this\n\t\t\t}\n\t\t\tthis.deleteRelation = (a, b) => {\n\t\t\t\texternalStore.deleteRelation(a, b)\n\t\t\t\treturn this\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\treturn this\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\treturn this\n\t\t\t\t}\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\t// @ts-expect-error we deduce hereby that this.b may index a\n\t\t\ttypeof rest[0] === `string` ? rest[0] : (a[this.b] 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\tthis.addRelation(a, b)\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\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 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\tfor (const subscriber of this.subscribers.values()) {\n\t\t\tsubscriber(value)\n\t\t}\n\t}\n}\n","import type {\n\tTransactionOptions,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \"atom.io\"\nimport { getState, setState } from \"atom.io\"\n\nimport { IMPLICIT, type Store, type StoreCore, deposit } 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<ƒ>) => ReturnType<ƒ>\n}\n\nexport function transaction__INTERNAL<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n\tstore: Store = IMPLICIT.STORE,\n): TransactionToken<ƒ> {\n\tconst newTransaction: Transaction<ƒ> = {\n\t\tkey: options.key,\n\t\ttype: `transaction`,\n\t\trun: (...params: Parameters<ƒ>) => {\n\t\t\tbuildTransaction(options.key, params, store)\n\t\t\ttry {\n\t\t\t\tconst output = options.do(\n\t\t\t\t\t{\n\t\t\t\t\t\tget: (token) => getState(token, store),\n\t\t\t\t\t\tset: (token, value) => setState(token, value, store),\n\t\t\t\t\t},\n\t\t\t\t\t...params,\n\t\t\t\t)\n\t\t\t\tapplyTransaction(output, store)\n\t\t\t\treturn output\n\t\t\t} catch (thrown) {\n\t\t\t\tabortTransaction(store)\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) => transaction__INTERNAL(options, store),\n\t\tsubject: new Subject(),\n\t}\n\tconst core = target(store)\n\tcore.transactions.set(newTransaction.key, newTransaction)\n\tconst token = deposit(newTransaction)\n\tstore.subject.transactionCreation.next(token)\n\treturn token\n}\n\nexport const target = (store: Store = IMPLICIT.STORE): StoreCore =>\n\tstore.transactionStatus.phase === `building`\n\t\t? store.transactionStatus.core\n\t\t: store\n","import type { Store } from \"../store\"\n\nexport const abortTransaction = (store: Store): void => {\n\tif (store.transactionStatus.phase === `idle`) {\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\tstore.transactionStatus.key,\n\t\t`Aborting transaction`,\n\t)\n\tstore.transactionStatus = { phase: `idle` }\n}\n","import type { AtomToken, ƒn } from \"atom.io\"\nimport { setState, transaction } from \"atom.io\"\n\nimport { withdraw } from \"../store\"\nimport type { Store } from \"../store\"\n\nexport const applyTransaction = <ƒ extends ƒn>(\n\toutput: ReturnType<ƒ>,\n\tstore: Store,\n): void => {\n\tif (store.transactionStatus.phase !== `building`) {\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\tstore.transactionStatus.phase = `applying`\n\tstore.transactionStatus.output = output\n\tconst { atomUpdates } = store.transactionStatus\n\tstore.logger.info(\n\t\t`🛄`,\n\t\t`transaction`,\n\t\tstore.transactionStatus.key,\n\t\t`Applying transaction with ${atomUpdates.length} updates:`,\n\t\tatomUpdates,\n\t)\n\n\tfor (const { key, newValue } of atomUpdates) {\n\t\tconst token: AtomToken<unknown> = { key, type: `atom` }\n\t\tif (!store.valueMap.has(token.key)) {\n\t\t\tif (token.family) {\n\t\t\t\tconst family = store.families.get(token.family.key)\n\t\t\t\tif (family) {\n\t\t\t\t\tfamily(token.family.subKey)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst newAtom = store.transactionStatus.core.atoms.get(token.key)\n\t\t\t\tif (!newAtom) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Absurd Error: Atom \"${token.key}\" not found while copying updates from transaction \"${store.transactionStatus.key}\" to store \"${store.config.name}\"`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tstore.atoms.set(newAtom.key, newAtom)\n\t\t\t\tstore.valueMap.set(newAtom.key, newAtom.default)\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🔨`,\n\t\t\t\t\t`transaction`,\n\t\t\t\t\tstore.transactionStatus.key,\n\t\t\t\t\t`Adding atom \"${newAtom.key}\"`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\t// if (store.transactionStatus.key === `dealCards`) debugger\n\t\tsetState(token, newValue, store)\n\t}\n\tconst myTransaction = withdraw<ƒ>(\n\t\t{ key: store.transactionStatus.key, type: `transaction` },\n\t\tstore,\n\t)\n\tif (myTransaction === undefined) {\n\t\tthrow new Error(\n\t\t\t`Transaction \"${store.transactionStatus.key}\" not found. Absurd. How is this running?`,\n\t\t)\n\t}\n\tmyTransaction.subject.next({\n\t\tkey: store.transactionStatus.key,\n\t\tatomUpdates,\n\t\toutput,\n\t\tparams: store.transactionStatus.params as Parameters<ƒ>,\n\t})\n\tstore.logger.info(\n\t\t`🛬`,\n\t\t`transaction`,\n\t\tstore.transactionStatus.key,\n\t\t`Finished applying transaction.`,\n\t)\n\tstore.transactionStatus = { phase: `idle` }\n}\n","import { Junction } from \"~/packages/rel8/junction/src\"\n\nimport type { Store } from \"../store\"\n\nexport const buildTransaction = (\n\tkey: string,\n\tparams: any[],\n\tstore: Store,\n): void => {\n\tstore.transactionStatus = {\n\t\tkey,\n\t\tphase: `building`,\n\t\ttime: Date.now(),\n\t\tcore: {\n\t\t\tatoms: new Map(store.atoms),\n\t\t\tatomsThatAreDefault: new Set(store.atomsThatAreDefault),\n\t\t\tfamilies: new Map(store.families),\n\t\t\toperation: { open: false },\n\t\t\treadonlySelectors: new Map(store.readonlySelectors),\n\t\t\ttimelines: new Map(store.timelines),\n\t\t\ttimelineAtoms: new Junction(store.timelineAtoms.toJSON()),\n\t\t\ttrackers: new Map(),\n\t\t\ttransactions: new Map(store.transactions),\n\t\t\tselectorAtoms: new Junction(store.selectorAtoms.toJSON()),\n\t\t\tselectorGraph: new Junction(store.selectorGraph.toJSON(), {\n\t\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t\t}),\n\t\t\tselectors: new Map(store.selectors),\n\t\t\tvalueMap: new Map(store.valueMap),\n\t\t},\n\t\tatomUpdates: [],\n\t\tparams,\n\t\toutput: undefined,\n\t}\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 { AtomToken, TransactionUpdate, ƒn } from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport { withdraw } from \"../store\"\nimport type { Store } from \"../store\"\n\nexport const redoTransactionUpdate = <ƒ extends ƒn>(\n\tupdate: TransactionUpdate<ƒ>,\n\tstore: Store,\n): void => {\n\tstore.logger.info(`⏭️`, `transaction`, update.key, `Redo`)\n\tfor (const { key, newValue } of update.atomUpdates) {\n\t\tconst token: AtomToken<unknown> = { key, type: `atom` }\n\t\tconst state = withdraw(token, store)\n\t\tif (state === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${token.key}\" not found in this store. This is surprising, because we are navigating the history of the store.`,\n\t\t\t)\n\t\t}\n\t\tsetState(state, newValue, store)\n\t}\n}\n","import type { AtomToken, TransactionUpdate, ƒn } from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport { withdraw } from \"../store\"\nimport type { Store } from \"../store\"\n\nexport const undoTransactionUpdate = <ƒ extends ƒn>(\n\tupdate: TransactionUpdate<ƒ>,\n\tstore: Store,\n): void => {\n\tstore.logger.info(\n\t\t`⏮️`,\n\t\t`transaction`,\n\t\tupdate.key,\n\t\t`Undoing transaction update`,\n\t\tupdate,\n\t)\n\tfor (const { key, oldValue } of update.atomUpdates) {\n\t\tconst token: AtomToken<unknown> = { key, type: `atom` }\n\t\tconst state = withdraw(token, store)\n\t\tif (state === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${token.key}\" not found in this store. This is surprising, because we are navigating the history of the store.`,\n\t\t\t)\n\t\t}\n\t\tsetState(state, oldValue, store)\n\t}\n}\n","import type { TransactionUpdate, ƒn } from \"atom.io\"\n\nimport type { StoreCore } from \"..\"\n\nexport * from \"./transaction-internal\"\n\nexport * from \"./abort-transaction\"\nexport * from \"./apply-transaction\"\nexport * from \"./build-transaction\"\nexport * from \"./redo-transaction\"\nexport * from \"./undo-transaction\"\n\nexport const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const\nexport type TransactionPhase = typeof TRANSACTION_PHASES[number]\n\nexport type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {\n\tphase: `applying` | `building`\n\ttime: number\n\tcore: StoreCore\n}\nexport type TransactionIdle = {\n\tphase: `idle`\n}\nexport type TransactionStatus<ƒ extends ƒn> =\n\t| TransactionIdle\n\t| TransactionUpdateInProgress<ƒ>\n","import type { AtomToken, TimelineUpdate } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { IMPLICIT, withdraw } from \"../store\"\nimport { target } from \"../transaction\"\nimport type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineTransactionUpdate,\n} from \"./timeline-internal\"\n\nexport const addAtomToTimeline = (\n\tatomToken: AtomToken<any>,\n\ttl: Timeline,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst atom = withdraw(atomToken, store)\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\tatom.subject.subscribe(`timeline`, (update) => {\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 =\n\t\t\tstore.transactionStatus.phase === `applying`\n\t\t\t\t? store.transactionStatus.key\n\t\t\t\t: null\n\t\tconst currentTransactionTime =\n\t\t\tstore.transactionStatus.phase === `applying`\n\t\t\t\t? store.transactionStatus.time\n\t\t\t\t: null\n\n\t\t// store.logger.info(\n\t\t// \t`⏳ timeline \"${tl.key}\" saw atom \"${atomToken.key}\" go (`,\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\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\n\t\tif (tl.timeTraveling === null) {\n\t\t\tif (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {\n\t\t\t\tconst mostRecentUpdate: TimelineUpdate | undefined = tl.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 (\n\t\t\t\tcurrentTransactionKey &&\n\t\t\t\tstore.transactionStatus.phase === `applying`\n\t\t\t) {\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 atomUpdates = update.atomUpdates.filter((atomUpdate) => {\n\t\t\t\t\t\t\t\t\tconst core = target(store)\n\t\t\t\t\t\t\t\t\tconst atomOrFamilyKeys = core.timelineAtoms.getRelatedKeys(\n\t\t\t\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\t\t\t\treturn atomOrFamilyKeys\n\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(key) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\tkey === atomUpdate.key ||\n\t\t\t\t\t\t\t\t\t\t\t\t\tkey === atomUpdate.family?.key,\n\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t: false\n\t\t\t\t\t\t\t\t})\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\tatomUpdates,\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 | 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 = {\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 { TimelineToken } from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\n\nexport const redo__INTERNAL = (\n\ttoken: TimelineToken,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tstore.logger.info(`⏩`, `timeline`, token.key, `redo`)\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 redo. This timeline has not been initialized.`,\n\t\t)\n\t\treturn\n\t}\n\tif (timelineData.at === timelineData.history.length) {\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 redo at the end of timeline \"${token.key}\". There is nothing to redo.`,\n\t\t)\n\t\treturn\n\t}\n\ttimelineData.timeTraveling = `into_future`\n\tconst update = timelineData.history[timelineData.at]\n\tswitch (update.type) {\n\t\tcase `atom_update`: {\n\t\t\tconst { key, newValue } = update\n\t\t\tsetState({ key, type: `atom` }, newValue, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `selector_update`:\n\t\tcase `transaction_update`: {\n\t\t\tfor (const atomUpdate of update.atomUpdates) {\n\t\t\t\tconst { key, newValue } = atomUpdate\n\t\t\t\tsetState({ key, type: `atom` }, newValue, store)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\t++timelineData.at\n\ttimelineData.subject.next(`redo`)\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\nexport const undo__INTERNAL = (\n\ttoken: TimelineToken,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tstore.logger.info(`⏪`, `timeline`, token.key, `undo`)\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 undo. This timeline has not been initialized.`,\n\t\t)\n\t\treturn\n\t}\n\tif (timelineData.at === 0) {\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 undo at the beginning of timeline \"${token.key}\". There is nothing to undo.`,\n\t\t)\n\t\treturn\n\t}\n\ttimelineData.timeTraveling = `into_past`\n\t--timelineData.at\n\tconst update = timelineData.history[timelineData.at]\n\tswitch (update.type) {\n\t\tcase `atom_update`: {\n\t\t\tconst { key, oldValue } = update\n\t\t\tsetState({ key, type: `atom` }, oldValue, store)\n\t\t\tbreak\n\t\t}\n\t\tcase `selector_update`:\n\t\tcase `transaction_update`: {\n\t\t\tfor (const atomUpdate of [...update.atomUpdates].reverse()) {\n\t\t\t\tconst { key, oldValue } = atomUpdate\n\t\t\t\tsetState({ key, type: `atom` }, oldValue, store)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\ttimelineData.subject.next(`undo`)\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 type {\n\tFamilyMetadata,\n\tStateUpdate,\n\tTimelineOptions,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionUpdate,\n\tƒn,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\nimport { addAtomToTimeline } from \"./add-atom-to-timeline\"\n\nexport type TimelineAtomUpdate = StateUpdate<unknown> & {\n\tkey: string\n\ttype: `atom_update`\n\ttimestamp: number\n\tfamily?: FamilyMetadata\n}\nexport type TimelineSelectorUpdate = {\n\tkey: string\n\ttype: `selector_update`\n\ttimestamp: number\n\tatomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[]\n}\nexport type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {\n\tkey: string\n\ttype: `transaction_update`\n\ttimestamp: number\n}\n\nexport type Timeline = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineUpdate[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: Store) => void\n\tsubject: Subject<\n\t\t| TimelineAtomUpdate\n\t\t| TimelineSelectorUpdate\n\t\t| TimelineTransactionUpdate\n\t\t| `redo`\n\t\t| `undo`\n\t>\n}\n\nexport function timeline__INTERNAL(\n\toptions: TimelineOptions,\n\tstore: Store = IMPLICIT.STORE,\n\tdata: Timeline | null = null,\n): TimelineToken {\n\tconst tl: Timeline = {\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) => timeline__INTERNAL(options, store, tl),\n\t\tsubject: new Subject(),\n\t}\n\tif (options.shouldCapture) {\n\t\ttl.shouldCapture = options.shouldCapture\n\t}\n\n\tconst core = target(store)\n\tfor (const tokenOrFamily of options.atoms) {\n\t\tconst timelineKey = core.timelineAtoms.getRelatedKey(tokenOrFamily.key)\n\t\tif (timelineKey) {\n\t\t\tstore.logger.error(\n\t\t\t\t`❌`,\n\t\t\t\t`timeline`,\n\t\t\t\toptions.key,\n\t\t\t\t`Failed to add atom \"${tokenOrFamily.key}\" because it already belongs to timeline \"${timelineKey}\"`,\n\t\t\t)\n\t\t\tcontinue\n\t\t}\n\t\tif (tokenOrFamily.type === `atom_family`) {\n\t\t\tconst family = tokenOrFamily\n\t\t\tfamily.subject.subscribe(`timeline:${options.key}`, (token) => {\n\t\t\t\t// if (!core.atoms.has(token.key)) {\n\t\t\t\taddAtomToTimeline(token, tl, store)\n\t\t\t\t// }\n\t\t\t})\n\t\t\tfor (const atom of core.atoms.values()) {\n\t\t\t\tif (atom.family?.key === family.key) {\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\tconst token = tokenOrFamily\n\t\t\tif (`family` in token && token.family) {\n\t\t\t\tconst familyTimelineKey = core.timelineAtoms.getRelatedKey(\n\t\t\t\t\ttoken.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 \"${token.key}\" because its family \"${token.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\taddAtomToTimeline(token, tl, store)\n\t\t}\n\t\tcore.timelineAtoms = core.timelineAtoms.set({\n\t\t\tatomKey: tokenOrFamily.key,\n\t\t\ttimelineKey: options.key,\n\t\t})\n\t}\n\n\tstore.timelines.set(options.key, tl)\n\tconst token: TimelineToken = {\n\t\tkey: options.key,\n\t\ttype: `timeline`,\n\t}\n\tstore.subject.timelineCreation.next(token)\n\treturn token\n}\n","import type {\n\tAtomToken,\n\tReadonlySelectorToken,\n\tSelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTransactionToken,\n\tƒn,\n} from \"atom.io\"\n\nimport type { Atom } from \"../atom\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport { addAtomToTimeline } from \"../timeline\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport { target } from \"../transaction\"\nimport type { Store } from \"./store\"\n\nexport function withdraw<T>(\n\ttoken: AtomToken<T>,\n\tstore: Store,\n): Atom<T> | undefined\nexport function withdraw<T>(\n\ttoken: SelectorToken<T>,\n\tstore: Store,\n): Selector<T> | undefined\nexport function withdraw<T>(\n\ttoken: StateToken<T>,\n\tstore: Store,\n): Atom<T> | Selector<T> | undefined\nexport function withdraw<T>(\n\ttoken: ReadonlySelectorToken<T>,\n\tstore: Store,\n): ReadonlySelector<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: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Store,\n): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined\nexport function withdraw<T>(\n\ttoken: TimelineToken,\n\tstore: Store,\n): Timeline | undefined\nexport function withdraw<T>(\n\ttoken:\n\t\t| ReadonlySelectorToken<T>\n\t\t| StateToken<T>\n\t\t| TimelineToken\n\t\t| TransactionToken<T>,\n\tstore: Store,\n):\n\t| Atom<T>\n\t| ReadonlySelector<T>\n\t| Selector<T>\n\t| Timeline\n\t| Transaction<T extends ƒn ? T : never>\n\t| undefined {\n\tlet core = target(store)\n\tlet state =\n\t\tcore.atoms.get(token.key) ??\n\t\tcore.selectors.get(token.key) ??\n\t\tcore.readonlySelectors.get(token.key) ??\n\t\tcore.transactions.get(token.key) ??\n\t\tcore.timelines.get(token.key)\n\tif (state) {\n\t\treturn state\n\t}\n\tif (store.transactionStatus.phase === `applying`) {\n\t\tcore = store.transactionStatus.core\n\t\tstate =\n\t\t\tcore.atoms.get(token.key) ??\n\t\t\tcore.selectors.get(token.key) ??\n\t\t\tcore.readonlySelectors.get(token.key) ??\n\t\t\tcore.transactions.get(token.key) ??\n\t\t\tcore.timelines.get(token.key)\n\n\t\tif (state) {\n\t\t\tstore.logger.info(\n\t\t\t\t`🛠️`,\n\t\t\t\ttoken.type,\n\t\t\t\ttoken.key,\n\t\t\t\t`add ${token.type} \"${token.key}\"`,\n\t\t\t)\n\t\t\tswitch (state.type) {\n\t\t\t\tcase `atom`: {\n\t\t\t\t\tstore.atoms.set(token.key, state)\n\t\t\t\t\tstore.valueMap.set(token.key, state.default)\n\t\t\t\t\tconst stateKey = state.key\n\t\t\t\t\tconst familyKey = state.family?.key\n\t\t\t\t\tlet timelineKey = core.timelineAtoms.getRelatedKey(stateKey)\n\t\t\t\t\tif (timelineKey === undefined && typeof familyKey === `string`) {\n\t\t\t\t\t\ttimelineKey = core.timelineAtoms.getRelatedKey(familyKey)\n\t\t\t\t\t}\n\t\t\t\t\tconst timeline =\n\t\t\t\t\t\ttypeof timelineKey === `string`\n\t\t\t\t\t\t\t? store.timelines.get(timelineKey)\n\t\t\t\t\t\t\t: undefined\n\n\t\t\t\t\tif (timeline) {\n\t\t\t\t\t\taddAtomToTimeline(state, timeline, store)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase `selector`:\n\t\t\t\t\tcore.selectors.set(token.key, state)\n\t\t\t\t\tbreak\n\t\t\t\tcase `readonly_selector`:\n\t\t\t\t\tcore.readonlySelectors.set(token.key, state)\n\t\t\t\t\tbreak\n\t\t\t\tcase `transaction`:\n\t\t\t\t\tcore.transactions.set(token.key, state)\n\t\t\t\t\tbreak\n\t\t\t\tcase `timeline`:\n\t\t\t\t\tcore.timelines.set(token.key, state)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t\treturn state\n\t\t}\n\t}\n\treturn undefined\n}\n","import type {\n\tAtomToken,\n\tReadonlySelectorToken,\n\tSelectorToken,\n\tStateToken,\n} from \"atom.io\"\nimport type { Atom, ReadonlySelector, Selector, Store } from \"..\"\nimport { withdraw } from \"..\"\nimport { target } from \"../transaction\"\n\nexport function withdrawNewFamilyMember<T>(\n\ttoken: AtomToken<T>,\n\tstore: Store,\n): Atom<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: SelectorToken<T>,\n\tstore: Store,\n): Selector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadonlySelectorToken<T>,\n\tstore: Store,\n): ReadonlySelector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: StateToken<T>,\n\tstore: Store,\n): Atom<T> | Selector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Store,\n): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken:\n\t\t| AtomToken<T>\n\t\t| ReadonlySelectorToken<T>\n\t\t| SelectorToken<T>\n\t\t| StateToken<T>,\n\tstore: Store,\n): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined {\n\tstore.logger.info(\n\t\t`👪`,\n\t\ttoken.type,\n\t\ttoken.key,\n\t\t`creating new family member in store \"${store.config.name}\"`,\n\t)\n\tif (token.family) {\n\t\tconst core = target(store)\n\t\tconst family = core.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","import type { StateUpdate } from \"atom.io\"\nimport { Future } from \"./future\"\nimport type { Store } from \"./store\"\nimport { IMPLICIT } from \"./store\"\nimport type { Subject } from \"./subject\"\nimport { target } from \"./transaction\"\n\nexport const cacheValue = (\n\tkey: string,\n\tvalue: unknown,\n\tsubject: Subject<StateUpdate<unknown>>,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentValue = target(store).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(value)\n\t\ttarget(store).valueMap.set(key, future)\n\t\tfuture\n\t\t\t.then((value) => {\n\t\t\t\tif (future.isCanceled) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tcacheValue(key, value, subject, store)\n\t\t\t\tsubject.next({ newValue: value, oldValue: value })\n\t\t\t})\n\t\t\t.catch((thrown) => {\n\t\t\t\tif (thrown !== `canceled`) {\n\t\t\t\t\tstore.logger.error(`💥`, `state`, key, `rejected:`, thrown)\n\t\t\t\t}\n\t\t\t})\n\t} else {\n\t\ttarget(store).valueMap.set(key, value)\n\t}\n}\n\nexport const readCachedValue = <T>(\n\tkey: string,\n\tstore: Store = IMPLICIT.STORE,\n): T => target(store).valueMap.get(key)\n\nexport const isValueCached = (\n\tkey: string,\n\tstore: Store = IMPLICIT.STORE,\n): boolean => target(store).valueMap.has(key)\n\nexport const evictCachedValue = (\n\tkey: string,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst core = target(store)\n\tconst currentValue = core.valueMap.get(key)\n\tif (currentValue instanceof Future) {\n\t\tcurrentValue.cancel()\n\t}\n\tif (core.operation.open) {\n\t\tcore.operation.prev.set(key, currentValue)\n\t}\n\tcore.valueMap.delete(key)\n\tstore.logger.info(`🗑`, `state`, key, `evicted`)\n}\n","import type { MutableAtomOptions, MutableAtomToken } from \"atom.io\"\nimport { subscribe } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJson } from \"atom.io/json\"\n\nimport { createAtom } from \"../atom\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport { target } from \"../transaction\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtom<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\toptions: MutableAtomOptions<Core, SerializableCore>,\n\tstore: Store = IMPLICIT.STORE,\n): MutableAtomToken<Core, SerializableCore> {\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 coreState = createAtom<Core>(options, undefined, store)\n\tnew Tracker(coreState, store)\n\tconst jsonState = selectJson(coreState, options, store)\n\tsubscribe(\n\t\tjsonState,\n\t\t() => {\n\t\t\tconst trackerHasBeenInitialized = target(store).trackers.has(coreState.key)\n\t\t\tif (!trackerHasBeenInitialized) {\n\t\t\t\tnew Tracker(coreState, store)\n\t\t\t}\n\t\t},\n\t\t`tracker-initializer:${store?.config.name}:${\n\t\t\tstore.transactionStatus.phase === `idle`\n\t\t\t\t? `main`\n\t\t\t\t: store.transactionStatus.key\n\t\t}`,\n\t)\n\treturn coreState as MutableAtomToken<Core, SerializableCore>\n}\n","import type { AtomToken, FamilyMetadata, MutableAtomToken } from \"atom.io\"\nimport { getState, setState, subscribe, subscribeToTimeline } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"..\"\nimport { IMPLICIT } from \"..\"\nimport { createAtom, deleteAtom } from \"../atom\"\nimport { target } from \"../transaction\"\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 = IMPLICIT.STORE,\n\t): AtomToken<typeof this.Update | null> {\n\t\tconst latestUpdateStateKey = `*${mutableState.key}`\n\t\tdeleteAtom({ type: `atom`, key: latestUpdateStateKey }, store)\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 = createAtom<\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\n\t\treturn latestUpdateState\n\t}\n\n\tprivate unsubscribeFromInnerValue: (() => void) | null = null\n\tprivate observeCore(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tlatestUpdateState: AtomToken<typeof this.Update | null>,\n\t\tstore: Store = IMPLICIT.STORE,\n\t): void {\n\t\tconst originalInnerValue = getState(mutableState, store)\n\t\tthis.unsubscribeFromInnerValue = originalInnerValue.subscribe(\n\t\t\t`tracker:${store.config.name}:${\n\t\t\t\tstore.transactionStatus.phase === `idle`\n\t\t\t\t\t? `main`\n\t\t\t\t\t: store.transactionStatus.key\n\t\t\t}`,\n\t\t\t(update) => {\n\t\t\t\tconst unsubscribe = store.subject.operationStatus.subscribe(\n\t\t\t\t\tmutableState.key,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\tsetState(latestUpdateState, update, store)\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t},\n\t\t)\n\t\tsubscribe(\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\tthis.unsubscribeFromInnerValue = update.newValue.subscribe(\n\t\t\t\t\t\t`tracker:${store.config.name}:${\n\t\t\t\t\t\t\tstore.transactionStatus.phase === `idle`\n\t\t\t\t\t\t\t\t? `main`\n\t\t\t\t\t\t\t\t: store.transactionStatus.key\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\tconst unsubscribe = store.subject.operationStatus.subscribe(\n\t\t\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\t\tsetState(latestUpdateState, update, store)\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\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: AtomToken<typeof this.Update | null>,\n\t\tstore: Store = IMPLICIT.STORE,\n\t): void {\n\t\tsubscribe(\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)\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.subject.operationStatus.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\tif (newValue) {\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: AtomToken<typeof this.Update | null>\n\n\tpublic constructor(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) {\n\t\tthis.mutableState = mutableState\n\t\tthis.latestUpdateState = this.initializeState(mutableState, store)\n\t\tthis.observeCore(mutableState, this.latestUpdateState, store)\n\t\tthis.updateCore(mutableState, this.latestUpdateState, store)\n\t\tconst core = target(store)\n\t\tcore.trackers.set(mutableState.key, this)\n\t}\n}\n","import type { MutableAtomFamily, MutableAtomFamilyOptions } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJsonFamily } from \"atom.io/json\"\n\nimport type { Store } from \"..\"\nimport { IMPLICIT, createAtomFamily } from \"..\"\nimport { FamilyTracker } from \"./tracker-family\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends string,\n>(\n\toptions: MutableAtomFamilyOptions<Core, SerializableCore, Key>,\n\tstore: Store = IMPLICIT.STORE,\n): MutableAtomFamily<Core, SerializableCore, Key> {\n\tconst coreFamily = Object.assign(\n\t\tcreateAtomFamily<Core, Key>(options, store),\n\t\toptions,\n\t) as MutableAtomFamily<Core, SerializableCore, Key>\n\tselectJsonFamily(coreFamily, options)\n\tnew FamilyTracker(coreFamily, store)\n\treturn coreFamily\n}\n","import type { AtomFamily } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport { createAtomFamily } from \"../families\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } 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: AtomFamily<\n\t\ttypeof this.Update | null,\n\t\tFamilyMemberKey\n\t>\n\tpublic readonly findMutableState: AtomFamily<Core, FamilyMemberKey>\n\n\tpublic constructor(\n\t\tfindMutableState: AtomFamily<Core, FamilyMemberKey>,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) {\n\t\tthis.findLatestUpdateState = createAtomFamily<\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\tAtomFamily,\n\tAtomFamilyOptions,\n\tAtomOptions,\n\tAtomToken,\n\tFamilyMetadata,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createAtom } from \"../atom\"\nimport { IMPLICIT, type Store, deposit, withdraw } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\n\nexport function createAtomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomFamily<T, K> {\n\tconst subject = new Subject<AtomToken<T>>()\n\tconst atomFamily = Object.assign(\n\t\t(key: K): AtomToken<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 = withdraw({ key: fullKey, type: `atom` }, store)\n\t\t\tlet token: AtomToken<any>\n\t\t\tif (existing) {\n\t\t\t\ttoken = deposit(existing)\n\t\t\t} else {\n\t\t\t\tconst individualOptions: AtomOptions<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\t// if (`toJson` in options && `fromJson` in options) {\n\t\t\t\t// \tindividualOptions.toJson = options.toJson\n\t\t\t\t// \tindividualOptions.fromJson\n\t\t\t\t// }\n\t\t\t\ttoken = createAtom<T>(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} as const,\n\t)\n\tconst core = target(store)\n\tcore.families.set(options.key, atomFamily)\n\treturn atomFamily\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 { createSelector } from \"../selector\"\nimport { type Store, deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\n\nexport function createReadonlySelectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n\tstore?: Store,\n): ReadonlySelectorFamily<T, K> {\n\tconst core = target(store)\n\tconst subject = new Subject<ReadonlySelectorToken<T>>()\n\treturn Object.assign(\n\t\t(key: K): ReadonlySelectorToken<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 = core.readonlySelectors.get(fullKey)\n\t\t\tif (existing) {\n\t\t\t\treturn deposit(existing)\n\t\t\t}\n\t\t\treturn createSelector<T>(\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} as const,\n\t) as ReadonlySelectorFamily<T, K>\n}\n","import type { Store } from \"./store\"\nimport { target } from \"./transaction\"\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\ttarget(store).atoms.has(key)\nexport const isSelectorKey = (\n\tkey: string,\n\tstore: Store,\n): key is SelectorKey<unknown> => target(store).selectors.has(key)\nexport const isReadonlySelectorKey = (\n\tkey: string,\n\tstore: Store,\n): key is ReadonlySelectorKey<unknown> =>\n\ttarget(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 type { Store } from \"../store\"\nimport { target } from \"../transaction\"\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 = target(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 { Atom } from \"./atom\"\nimport { isValueCached, readCachedValue } from \"./caching\"\nimport type { ReadonlySelector, Selector } from \"./selector\"\nimport type { Store } from \"./store\"\nimport { IMPLICIT } from \"./store\"\n\nexport const getState__INTERNAL = <T>(\n\tstate: Atom<T> | ReadonlySelector<T> | Selector<T>,\n\tstore: Store = IMPLICIT.STORE,\n): T => {\n\tif (isValueCached(state.key, store)) {\n\t\tstore.logger.info(`📖`, state.type, state.key, `reading cached value`)\n\t\treturn readCachedValue(state.key, store)\n\t}\n\tif (state.type !== `atom`) {\n\t\tstore.logger.info(`🧮`, state.type, state.key, `calculating value`)\n\t\treturn state.get()\n\t}\n\tstore.logger.error(`🐞`, `atom`, state.key, `could not find cached value`)\n\treturn state.default\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 { StateToken } from \"atom.io\"\n\nimport type { Store } from \"./store\"\nimport { IMPLICIT } from \"./store\"\nimport { target } from \"./transaction\"\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: StateToken<any>\n\t }\n\nexport const openOperation = (\n\ttoken: StateToken<any>,\n\tstore: Store,\n): `rejection` | undefined => {\n\tconst core = target(store)\n\tif (core.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 \"${core.operation.token.key}\"`,\n\t\t)\n\t\treturn `rejection`\n\t}\n\tcore.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.transactionStatus.phase === `idle`\n\t\t\t\t? ``\n\t\t\t\t: ` ${store.transactionStatus.phase} \"${store.transactionStatus.key}\"`\n\t\t}`,\n\t)\n}\nexport const closeOperation = (store: Store): void => {\n\tconst core = target(store)\n\tif (core.operation.open) {\n\t\tstore.logger.info(\n\t\t\t`🔴`,\n\t\t\tcore.operation.token.type,\n\t\t\tcore.operation.token.key,\n\t\t\t`operation done in store \"${store.config.name}\"`,\n\t\t)\n\t}\n\tcore.operation = { open: false }\n\tstore.subject.operationStatus.next(core.operation)\n}\n\nexport const isDone = (key: string, store: Store = IMPLICIT.STORE): boolean => {\n\tconst core = target(store)\n\tif (!core.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 core.operation.done.has(key)\n}\nexport const markDone = (key: string, store: Store = IMPLICIT.STORE): void => {\n\tconst core = target(store)\n\tif (!core.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\tcore.operation.done.add(key)\n}\n","import type { JsonInterface } from \"atom.io/json\"\n\nimport type { Atom } from \"../atom\"\nimport { Tracker } from \"../mutable\"\nimport type { Store, StoreCore } from \"../store\"\n\nexport function copyMutableIfNeeded<T>(\n\tatom: Atom<T>,\n\ttransform: JsonInterface<T>,\n\torigin: Store,\n\ttarget: StoreCore,\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 copiedValue = transform.fromJson(transform.toJson(originValue))\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 type { AtomFamily } from \"atom.io\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\nimport { getState__INTERNAL } from \"..\"\nimport type { Store, StoreCore } from \"..\"\nimport type { Atom } from \"../atom\"\nimport { copyMutableIfNeeded } from \"./copy-mutable-if-needed\"\n\nexport function copyMutableIfWithinTransaction<T>(\n\tatom: Atom<T> | (Atom<T> & JsonInterface<T, Json.Serializable>),\n\tstore: Store,\n): T {\n\tif (\n\t\tstore.transactionStatus.phase === `building` ||\n\t\tstore.transactionStatus.phase === `applying`\n\t) {\n\t\tif (`toJson` in atom && `fromJson` in atom) {\n\t\t\tconst copiedValue = copyMutableIfNeeded(\n\t\t\t\tatom,\n\t\t\t\tatom,\n\t\t\t\tstore,\n\t\t\t\tstore.transactionStatus.core,\n\t\t\t)\n\t\t\treturn copiedValue\n\t\t}\n\t\tif (`family` in atom) {\n\t\t\tconst family = store.transactionStatus.core.families.get(atom.family.key)\n\t\t\tif (family && family.type === `atom_family`) {\n\t\t\t\tconst result = copyMutableFamilyMemberWithinTransaction<T>(\n\t\t\t\t\tatom,\n\t\t\t\t\tfamily,\n\t\t\t\t\tstore,\n\t\t\t\t\tstore.transactionStatus.core,\n\t\t\t\t)\n\t\t\t\tif (result) {\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn getState__INTERNAL(atom, store)\n}\n\nexport function copyMutableFamilyMemberWithinTransaction<T>(\n\tatom: Atom<T>,\n\tfamily:\n\t\t| AtomFamily<T, any>\n\t\t| (AtomFamily<T, any> & JsonInterface<T, Json.Serializable>),\n\torigin: Store,\n\ttarget: StoreCore,\n): T | null {\n\tif (`toJson` in family && `fromJson` in family) {\n\t\tconst copyCreated = copyMutableIfNeeded(atom, family, origin, target)\n\t\treturn copyCreated\n\t}\n\treturn null\n}\n","import type { StateUpdate } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\n\nimport type { Atom } from \"../atom\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\n\nexport const emitUpdate = <T>(\n\tstate: Atom<T> | ReadonlySelector<T> | Selector<T>,\n\tupdate: StateUpdate<T>,\n\tstore: Store,\n): void => {\n\tconst { key } = state\n\tconst { logger } = store\n\tlogger.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 \"../atom\"\nimport { evictCachedValue } from \"../caching\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport { target } from \"../transaction\"\n\nexport const evictDownStream = <T>(\n\tatom: Atom<T>,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst core = target(store)\n\tconst downstreamKeys = core.selectorAtoms.getRelatedKeys(atom.key)\n\tstore.logger.info(\n\t\t`🧹`,\n\t\tatom.type,\n\t\tatom.key,\n\t\t`evicting ${downstreamKeys?.size ?? 0} states downstream:`,\n\t\tdownstreamKeys,\n\t)\n\tif (downstreamKeys !== undefined) {\n\t\tif (core.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`[ ${[...core.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 \"../atom\"\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, unless they're not equal by reference\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\tif (store.transactionStatus.phase !== `building`) {\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\tstore.transactionStatus.atomUpdates.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 \"../atom\"\nimport { isAtomDefault, markAtomAsNotDefault } from \"../atom\"\nimport { cacheValue } from \"../caching\"\nimport { getState__INTERNAL } from \"../get-state-internal\"\nimport { markDone } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } 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\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst oldValue = getState__INTERNAL(atom, store)\n\tlet newValue = copyMutableIfWithinTransaction(atom, store)\n\tnewValue = become(next)(newValue)\n\tstore.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)\n\tcacheValue(atom.key, newValue, atom.subject, store)\n\tif (isAtomDefault(atom.key, store)) {\n\t\tmarkAtomAsNotDefault(atom.key, store)\n\t}\n\tmarkDone(atom.key, store)\n\tevictDownStream(atom, store)\n\tconst update = { oldValue, newValue }\n\tif (store.transactionStatus.phase !== `building`) {\n\t\temitUpdate(atom, update, store)\n\t} else {\n\t\tstowUpdate(atom, update, store)\n\t}\n}\n","import type { Atom } from \"../atom\"\nimport type { Selector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport { setAtom } from \"./set-atom\"\n\nexport const setState__INTERNAL = <T>(\n\tstate: Atom<T> | Selector<T>,\n\tvalue: T | ((oldValue: T) => T),\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tif (state.type === `selector`) {\n\t\tstate.set(value)\n\t} else {\n\t\tsetAtom(state, value, store)\n\t}\n}\n","import type { 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\tselectorKey: string,\n\tstore: Store,\n): AtomKey<unknown>[] => {\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, StateToken } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { target } from \"../transaction\"\nimport { traceSelectorAtoms } from \"./trace-selector-atoms\"\n\nexport const updateSelectorAtoms = (\n\tselectorKey: string,\n\tdependency: ReadonlySelectorToken<unknown> | StateToken<unknown>,\n\tstore: Store,\n): void => {\n\tconst core = target(store)\n\tif (dependency.type === `atom`) {\n\t\tcore.selectorAtoms = core.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\tcore.selectorAtoms = core.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 { Transactors } from \"atom.io\"\n\nimport { getState__INTERNAL } from \"../get-state-internal\"\nimport { setState__INTERNAL } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT, withdraw } from \"../store\"\nimport { target } from \"../transaction/transaction-internal\"\nimport { updateSelectorAtoms } from \"./update-selector-atoms\"\n\nexport const registerSelector = (\n\tselectorKey: string,\n\tstore: Store = IMPLICIT.STORE,\n): Transactors => ({\n\tget: (dependency) => {\n\t\tconst core = target(store)\n\t\tconst alreadyRegistered = core.selectorGraph\n\t\t\t.getRelationEntries({ downstreamSelectorKey: selectorKey })\n\t\t\t.some(([_, { source }]) => source === dependency.key)\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 = getState__INTERNAL(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\tif (!alreadyRegistered) {\n\t\t\tcore.selectorGraph = core.selectorGraph.set(\n\t\t\t\t{\n\t\t\t\t\tupstreamSelectorKey: dependency.key,\n\t\t\t\t\tdownstreamSelectorKey: selectorKey,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tsource: dependency.key,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\tupdateSelectorAtoms(selectorKey, dependency, store)\n\t\treturn dependencyValue\n\t},\n\tset: (stateToken, newValue) => {\n\t\tconst state = withdraw(stateToken, store)\n\t\tif (state === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${stateToken.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\tsetState__INTERNAL(state, newValue, store)\n\t},\n})\n","import type { FamilyMetadata, SelectorOptions, SelectorToken } from \"atom.io\"\n\nimport { cacheValue } from \"../caching\"\nimport { markDone } from \"../operation\"\nimport { become } from \"../set-state/become\"\nimport type { Store, StoreCore } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { Selector } from \"./create-selector\"\nimport { createSelector } from \"./create-selector\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadWriteSelector = <T>(\n\toptions: SelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n\tcore: StoreCore,\n): SelectorToken<T> => {\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\n\tconst { get, set } = registerSelector(options.key, store)\n\tconst getSelf = () => {\n\t\tconst value = options.get({ get })\n\t\tcacheValue(options.key, value, subject, 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\t// store.logger.info(`📝 set \"${options.key}\" (`, oldValue, `->`, newValue, `)`)\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 (store.transactionStatus.phase === `idle`) {\n\t\t\tsubject.next({ newValue, oldValue })\n\t\t}\n\t\toptions.set({ get, set }, newValue)\n\t}\n\tconst mySelector: Selector<T> = {\n\t\t...options,\n\t\tsubject,\n\t\tinstall: (s: Store) => createSelector(options, family, s),\n\t\tget: getSelf,\n\t\tset: setSelf,\n\t\ttype: `selector`,\n\t\t...(family && { family }),\n\t}\n\tcore.selectors.set(options.key, mySelector)\n\tconst initialValue = getSelf()\n\tstore.logger.info(`✨`, mySelector.type, mySelector.key, `=`, initialValue)\n\tconst token: SelectorToken<T> = {\n\t\tkey: options.key,\n\t\ttype: `selector`,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\tstore.subject.selectorCreation.next(token)\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorOptions,\n\tReadonlySelectorToken,\n} from \"atom.io\"\n\nimport { cacheValue } from \"../caching\"\nimport type { Store, StoreCore } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { ReadonlySelector } from \"./create-selector\"\nimport { createSelector } from \"./create-selector\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadonlySelector = <T>(\n\toptions: ReadonlySelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n\tcore: StoreCore,\n): ReadonlySelectorToken<T> => {\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\n\tconst { get } = registerSelector(options.key, store)\n\tconst getSelf = () => {\n\t\tconst value = options.get({ get })\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) => createSelector(options, family, s),\n\t\tget: getSelf,\n\t\ttype: `readonly_selector`,\n\t\t...(family && { family }),\n\t}\n\tcore.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.subject.selectorCreation.next(token)\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorOptions,\n\tReadonlySelectorToken,\n\tSelectorOptions,\n\tSelectorToken,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\nimport { createReadWriteSelector } from \"./create-read-write-selector\"\nimport { createReadonlySelector } from \"./create-readonly-selector\"\n\nexport type Selector<T> = {\n\tkey: string\n\ttype: `selector`\n\tfamily?: FamilyMetadata\n\tinstall: (store: Store) => void\n\tsubject: Subject<{ newValue: T; oldValue: T }>\n\tget: () => T\n\tset: (newValue: T | ((oldValue: T) => T)) => void\n}\nexport type ReadonlySelector<T> = {\n\tkey: string\n\ttype: `readonly_selector`\n\tfamily?: FamilyMetadata\n\tinstall: (store: Store) => void\n\tsubject: Subject<{ newValue: T; oldValue: T }>\n\tget: () => T\n}\n\nexport function createSelector<T>(\n\toptions: SelectorOptions<T>,\n\tfamily?: FamilyMetadata,\n\tstore?: Store,\n): SelectorToken<T>\nexport function createSelector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n\tfamily?: FamilyMetadata,\n\tstore?: Store,\n): ReadonlySelectorToken<T>\nexport function createSelector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n\tfamily?: FamilyMetadata,\n\tstore: Store = IMPLICIT.STORE,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\tconst core = target(store)\n\tconst existingWritable = core.selectors.get(options.key)\n\tconst existingReadonly = core.readonlySelectors.get(options.key)\n\n\tif (existingWritable || existingReadonly) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\texistingReadonly ? `readonly_selector` : `selector`,\n\t\t\toptions.key,\n\t\t\t`Tried to create selector, but it already exists in the store. (Ignore if you are in development using hot module replacement.)`,\n\t\t)\n\t}\n\n\tif (`set` in options) {\n\t\treturn createReadWriteSelector(options, family, store, core)\n\t}\n\treturn createReadonlySelector(options, family, store, core)\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorFamily,\n\tReadonlySelectorFamilyOptions,\n\tSelectorFamily,\n\tSelectorFamilyOptions,\n\tSelectorToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT, deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\nimport { createReadonlySelectorFamily } from \"./create-readonly-selector-family\"\n\nexport function createSelectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n\tstore?: Store,\n): SelectorFamily<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: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n\tstore: Store = IMPLICIT.STORE,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\tconst isReadonly = !(`set` in options)\n\n\tif (isReadonly) {\n\t\treturn createReadonlySelectorFamily(options, store)\n\t}\n\tconst core = target(store)\n\tconst subject = new Subject<SelectorToken<T>>()\n\n\tconst selectorFamily = Object.assign(\n\t\t(key: K): SelectorToken<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 = core.selectors.get(fullKey)\n\t\t\tif (existing) {\n\t\t\t\treturn deposit(existing)\n\t\t\t}\n\t\t\tconst token = createSelector<T>(\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} as const,\n\t) as SelectorFamily<T, K>\n\tcore.families.set(options.key, selectorFamily)\n\treturn selectorFamily\n}\n","import type { MutableAtomToken, SelectorToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonToken = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): SelectorToken<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: SelectorToken<SerializableCore> = { type: `selector`, key }\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 { AtomToken, MutableAtomToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport type { Signal, Transceiver } from \"./transceiver\"\n\nexport const getUpdateToken = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): AtomToken<Signal<Core>> => {\n\tconst key = `*${mutableAtomToken.key}`\n\tconst updateToken: AtomToken<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 { AtomToken, MutableAtomToken } from \"atom.io\"\n\nexport function isAtomTokenMutable(\n\ttoken: AtomToken<any>,\n): token is MutableAtomToken<any, any> {\n\treturn token.key.endsWith(`::mutable`)\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}\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 { Atom } from \"../atom\"\n\nexport * from \"./create-mutable-atom\"\nexport * from \"./create-mutable-atom-family\"\nexport * from \"./get-json-token\"\nexport * from \"./get-update-token\"\nexport * from \"./is-atom-token-mutable\"\nexport * from \"./tracker\"\nexport * from \"./tracker-family\"\nexport * from \"./transceiver\"\n\nexport interface MutableAtom<T> extends Atom<T> {\n\tmutable: true\n}\n\nexport const isAtomMutable = <T>(atom: Atom<T>): atom is MutableAtom<T> =>\n\t`isMutable` in atom\n","import { traceAllSelectorAtoms } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport { target } from \"../transaction\"\n\nexport const isAtomDefault = (\n\tkey: string,\n\tstore: Store = IMPLICIT.STORE,\n): boolean => {\n\tconst core = target(store)\n\treturn core.atomsThatAreDefault.has(key)\n}\n\nexport const markAtomAsDefault = (\n\tkey: string,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst core = target(store)\n\tcore.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key)\n}\n\nexport const markAtomAsNotDefault = (\n\tkey: string,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst core = target(store)\n\tcore.atomsThatAreDefault = new Set(target(store).atomsThatAreDefault)\n\tcore.atomsThatAreDefault.delete(key)\n}\n\nexport const isSelectorDefault = (\n\tkey: string,\n\tstore: Store = IMPLICIT.STORE,\n): boolean => {\n\tconst rootKeys = traceAllSelectorAtoms(key, store)\n\treturn rootKeys.every((rootKey) => isAtomDefault(rootKey, store))\n}\n","import type { AtomToken } from \"~/packages/atom.io/src\"\nimport type { Store } from \"..\"\nimport { IMPLICIT, target } from \"..\"\n\nexport function deleteAtom(\n\tatomToken: AtomToken<unknown>,\n\tstore: Store = IMPLICIT.STORE,\n): void {\n\tconst core = target(store)\n\tconst { key } = atomToken\n\tcore.atoms.delete(key)\n\tcore.valueMap.delete(key)\n\tcore.selectorAtoms.delete(key)\n\tcore.atomsThatAreDefault.delete(key)\n\tcore.timelineAtoms.delete(key)\n\tstore.logger.info(`🔥`, `atom`, `${key}`, `deleted`)\n}\n","import type { Atom } from \"../atom\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport { target } from \"../transaction\"\n\nexport const recallState = <T>(\n\tstate: Atom<T> | ReadonlySelector<T> | Selector<T>,\n\tstore: Store = IMPLICIT.STORE,\n): T => {\n\tconst core = target(store)\n\tif (!core.operation.open) {\n\t\tstore.logger.warn(\n\t\t\t`🐞`,\n\t\t\tstate.type,\n\t\t\tstate.key,\n\t\t\t`recall called outside of an operation. This is probably a bug.`,\n\t\t)\n\t\treturn core.valueMap.get(state.key)\n\t}\n\treturn core.operation.prev.get(state.key)\n}\n","import { getState__INTERNAL } from \"../get-state-internal\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport { traceAllSelectorAtoms } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { recallState } from \"./recall-state\"\n\nexport const subscribeToRootAtoms = <T>(\n\tstate: ReadonlySelector<T> | Selector<T>,\n\tstore: Store,\n): (() => void)[] | null => {\n\tconst dependencySubscriptions =\n\t\t`default` in state\n\t\t\t? null\n\t\t\t: traceAllSelectorAtoms(state.key, store).map((atomKey) => {\n\t\t\t\t\tconst atom = store.atoms.get(atomKey)\n\t\t\t\t\tif (atom === undefined) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Atom \"${atomKey}\", a dependency of selector \"${state.key}\", not found in store \"${store.config.name}\".`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\treturn atom.subject.subscribe(\n\t\t\t\t\t\t`${state.type}:${state.key}`,\n\t\t\t\t\t\t(atomChange) => {\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\tstate.type,\n\t\t\t\t\t\t\t\tstate.key,\n\t\t\t\t\t\t\t\t`root`,\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\t`went`,\n\t\t\t\t\t\t\t\tatomChange.oldValue,\n\t\t\t\t\t\t\t\t`->`,\n\t\t\t\t\t\t\t\tatomChange.newValue,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tconst oldValue = recallState(state, store)\n\t\t\t\t\t\t\t// ❌ this retrieves a stale cached value when applying a transaction on the server\n\t\t\t\t\t\t\tconst newValue = getState__INTERNAL(state, store)\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\tstate.type,\n\t\t\t\t\t\t\t\tstate.key,\n\t\t\t\t\t\t\t\t`went`,\n\t\t\t\t\t\t\t\toldValue,\n\t\t\t\t\t\t\t\t`->`,\n\t\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tstate.subject.next({ newValue, oldValue })\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t })\n\treturn dependencySubscriptions\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/atom/create-atom.ts","../src/future.ts","../src/transaction/abort-transaction.ts","../src/transaction/apply-transaction.ts","../src/store/deposit.ts","../src/store/store.ts","../../../rel8/junction/src/junction.ts","../src/subject.ts","../src/timeline/add-atom-to-timeline.ts","../src/timeline/create-timeline.ts","../src/timeline/time-travel.ts","../src/store/withdraw.ts","../src/store/withdraw-new-family-member.ts","../src/transaction/build-transaction.ts","../src/transaction/create-transaction.ts","../src/transaction/redo-transaction.ts","../src/transaction/undo-transaction.ts","../src/transaction/index.ts","../src/caching.ts","../src/mutable/create-mutable-atom.ts","../src/mutable/tracker.ts","../src/mutable/create-mutable-atom-family.ts","../src/mutable/tracker-family.ts","../src/families/create-atom-family.ts","../src/families/create-readonly-selector-family.ts","../src/operation.ts","../src/set-state/become.ts","../src/read-or-compute-value.ts","../src/set-state/copy-mutable-if-needed.ts","../src/set-state/copy-mutable-in-transaction.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/register-selector.ts","../src/selector/create-read-write-selector.ts","../src/selector/create-readonly-selector.ts","../src/selector/create-selector.ts","../src/selector/delete-selector.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-atom-token-mutable.ts","../src/mutable/transceiver.ts","../src/mutable/index.ts","../src/atom/is-default.ts","../src/atom/delete-atom.ts","../src/not-found-error.ts","../src/subscribe/recall-state.ts","../src/subscribe/subscribe-to-root-atoms.ts"],"names":["setState","subscribe","a","b","update","_a","_b","store","token","getState","unsubscribe","stringifyJson","target"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOA,SAAS,YAAAA,WAAU,aAAAC,kBAAiB;;;ACE7B,IAAM,SAAN,cAAwB,QAAW;AAAA,EAGlC,YACN,UAGC;AACD,UAAM,CAAC,SAAS,WAAW;AAC1B,YAAM,OAAO,CAAC,UACb,KAAK,aAAa,OAAO,UAAU,IAAI,QAAQ,KAAK;AACrD,YAAM,OAAO,CAAC,WACb,KAAK,aAAa,OAAO,UAAU,IAAI,OAAO,MAAM;AACrD,UAAI,OAAO,aAAa,YAAY;AACnC,iBAAS,MAAM,IAAI;AAAA,MACpB,OAAO;AACN,iBAAS,KAAK,MAAM,IAAI;AA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;AAAA,MACnB,GAAG,MAAM,IAAI,IAAI,MAAM,GAAG;AAAA,MAC1B,CAAC,eAAe;AACf,cAAM,OAAO;AAAA,UACZ;AAAA,UACA,MAAM;AAAA,UACN,MAAM;AAAA,UACN;AAAA,UACA;AAAA,UACA;AAAA,UACA,WAAW;AAAA,UACX;AAAA,UACA,WAAW;AAAA,QACZ;AACA,cAAM,WAAW,YAAY,OAAO,KAAK;AAEzC,cAAM,WAAW,mBAAmB,OAAO,KAAK;AAChD,cAAM,OAAO;AAAA,UACZ;AAAA,UACA,MAAM;AAAA,UACN,MAAM;AAAA,UACN;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACD;AACA,cAAM,QAAQ,KAAK,EAAE,UAAU,SAAS,CAAC;AAAA,MAC1C;AAAA,IACD;AAAA,EACA,CAAC;AACL,SAAO;AACR","sourcesContent":["import type {\n\tAtomOptions,\n\tAtomToken,\n\tFamilyMetadata,\n\tMutableAtomOptions,\n\tUpdateHandler,\n} from \"atom.io\"\nimport { setState, subscribe } from \"atom.io\"\n\nimport { cacheValue } from \"../caching\"\nimport { createMutableAtom } from \"../mutable\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\nimport { markAtomAsDefault } from \"./is-default\"\n\nexport type Atom<T> = {\n\tkey: string\n\ttype: `atom`\n\tfamily?: FamilyMetadata\n\tinstall: (store: Store) => void\n\tsubject: Subject<{ newValue: T; oldValue: T }>\n\tdefault: T | (() => T)\n\tcleanup?: () => void\n}\n\nexport function createAtom<T>(\n\toptions: AtomOptions<T> | MutableAtomOptions<any, any>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): AtomToken<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 core = target(store)\n\tconst existing = core.atoms.get(options.key)\n\tif (existing) {\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\t`(Ignore if you are in development using hot module replacement.)`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: Atom<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 `mutable` in options\n\t\t\t\t? createMutableAtom(options, store)\n\t\t\t\t: createAtom(options, undefined, store)\n\t\t},\n\t\tsubject,\n\t\t...(family && { family }),\n\t} as const\n\tlet initialValue = options.default\n\tif (options.default instanceof Function) {\n\t\tinitialValue = options.default()\n\t}\n\tcore.atoms.set(newAtom.key, newAtom)\n\tmarkAtomAsDefault(options.key, store)\n\tcacheValue(options.key, initialValue, subject, store)\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\tsubscribe(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.subject.atomCreation.next(token)\n\treturn token as AtomToken<T>\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 { Store } from \"../store\"\n\nexport const abortTransaction = (store: Store): void => {\n\tif (store.transactionStatus.phase === `idle`) {\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\tstore.transactionStatus.key,\n\t\t`Aborting transaction`,\n\t)\n\tstore.transactionStatus = { phase: `idle` }\n}\n","import type { AtomToken, ƒn } from \"atom.io\"\nimport { setState, transaction } from \"atom.io\"\n\nimport { withdraw } from \"../store\"\nimport type { Store } from \"../store\"\n\nexport const applyTransaction = <ƒ extends ƒn>(\n\toutput: ReturnType<ƒ>,\n\tstore: Store,\n): void => {\n\tif (store.transactionStatus.phase !== `building`) {\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\tstore.transactionStatus.phase = `applying`\n\tstore.transactionStatus.output = output\n\tconst { atomUpdates } = store.transactionStatus\n\tstore.logger.info(\n\t\t`🛄`,\n\t\t`transaction`,\n\t\tstore.transactionStatus.key,\n\t\t`Applying transaction with ${atomUpdates.length} updates:`,\n\t\tatomUpdates,\n\t)\n\n\tfor (const { key, newValue } of atomUpdates) {\n\t\tconst token: AtomToken<unknown> = { key, type: `atom` }\n\t\tif (!store.valueMap.has(token.key)) {\n\t\t\tif (token.family) {\n\t\t\t\tconst family = store.families.get(token.family.key)\n\t\t\t\tif (family) {\n\t\t\t\t\tfamily(token.family.subKey)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst newAtom = store.transactionStatus.core.atoms.get(token.key)\n\t\t\t\tif (!newAtom) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Absurd Error: Atom \"${token.key}\" not found while copying updates from transaction \"${store.transactionStatus.key}\" to store \"${store.config.name}\"`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tstore.atoms.set(newAtom.key, newAtom)\n\t\t\t\tstore.valueMap.set(newAtom.key, newAtom.default)\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🔨`,\n\t\t\t\t\t`transaction`,\n\t\t\t\t\tstore.transactionStatus.key,\n\t\t\t\t\t`Adding atom \"${newAtom.key}\"`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\t// if (store.transactionStatus.key === `dealCards`) debugger\n\t\tsetState(token, newValue, store)\n\t}\n\tconst myTransaction = withdraw<ƒ>(\n\t\t{ key: store.transactionStatus.key, type: `transaction` },\n\t\tstore,\n\t)\n\tif (myTransaction === undefined) {\n\t\tthrow new Error(\n\t\t\t`Transaction \"${store.transactionStatus.key}\" not found. Absurd. How is this running?`,\n\t\t)\n\t}\n\tmyTransaction.subject.next({\n\t\tkey: store.transactionStatus.key,\n\t\tatomUpdates,\n\t\toutput,\n\t\tparams: store.transactionStatus.params as Parameters<ƒ>,\n\t})\n\tstore.logger.info(\n\t\t`🛬`,\n\t\t`transaction`,\n\t\tstore.transactionStatus.key,\n\t\t`Finished applying transaction.`,\n\t)\n\tstore.transactionStatus = { phase: `idle` }\n}\n","import type {\n\tAtomToken,\n\tReadonlySelectorToken,\n\tSelectorToken,\n\tStateToken,\n\tTransactionToken,\n\tƒn,\n} from \"atom.io\"\n\nimport type { Atom } from \"../atom\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport type { Transaction } from \"../transaction\"\n\nexport function deposit<T>(state: Atom<T>): AtomToken<T>\nexport function deposit<T>(state: Selector<T>): SelectorToken<T>\nexport function deposit<T>(state: Atom<T> | Selector<T>): StateToken<T>\nexport function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>\nexport function deposit<T>(\n\tstate: Transaction<T extends ƒn ? T : never>,\n): TransactionToken<T>\nexport function deposit<T>(\n\tstate: Atom<T> | ReadonlySelector<T> | Selector<T>,\n): ReadonlySelectorToken<T> | StateToken<T>\nexport function deposit<T>(\n\tstate:\n\t\t| Atom<T>\n\t\t| ReadonlySelector<T>\n\t\t| Selector<T>\n\t\t| Transaction<T extends ƒn ? T : never>,\n):\n\t| AtomToken<T>\n\t| ReadonlySelectorToken<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, simpleLogger } from \"atom.io\"\nimport type {\n\tAtomFamily,\n\tAtomToken,\n\tLogger,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tSelectorFamily,\n\tSelectorToken,\n\tTimelineToken,\n\tTransactionToken,\n\tƒn,\n} from \"atom.io\"\n\nimport { Junction } from \"~/packages/rel8/junction/src\"\n\nimport type { Atom } from \"../atom\"\nimport type { MutableAtom, Tracker, Transceiver } from \"../mutable\"\nimport type { OperationProgress } from \"../operation\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport { Subject } from \"../subject\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction, TransactionStatus } from \"../transaction\"\n\nexport type StoreCore = Pick<\n\tStore,\n\t| `atoms`\n\t| `atomsThatAreDefault`\n\t| `families`\n\t| `operation`\n\t| `readonlySelectors`\n\t| `selectorAtoms`\n\t| `selectorGraph`\n\t| `selectors`\n\t| `timelineAtoms`\n\t| `timelines`\n\t| `trackers`\n\t| `transactions`\n\t| `valueMap`\n>\n\nexport class Store {\n\tpublic valueMap = new Map<string, any>()\n\n\tpublic atoms = new Map<string, Atom<any> | MutableAtom<any>>()\n\tpublic selectors = new Map<string, Selector<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| AtomFamily<any, any>\n\t\t| ReadonlySelectorFamily<any, any>\n\t\t| SelectorFamily<any, any>\n\t>()\n\n\tpublic timelines = new Map<string, Timeline>()\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 subject = {\n\t\tatomCreation: new Subject<AtomToken<unknown>>(),\n\t\tselectorCreation: new Subject<\n\t\t\tReadonlySelectorToken<unknown> | SelectorToken<unknown>\n\t\t>(),\n\t\ttransactionCreation: new Subject<TransactionToken<ƒn>>(),\n\t\ttimelineCreation: new Subject<TimelineToken>(),\n\t\toperationStatus: new Subject<OperationProgress>(),\n\t}\n\tpublic operation: OperationProgress = { open: false }\n\tpublic transactionStatus: TransactionStatus<ƒn> = { phase: `idle` }\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.transactionStatus = { ...store?.transactionStatus }\n\t\t\tthis.config = {\n\t\t\t\t...store?.config,\n\t\t\t\tname,\n\t\t\t}\n\n\t\t\tfor (const [, atom] of store.atoms) {\n\t\t\t\tatom.install(this)\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\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\tfor (const subscriber of this.subscribers.values()) {\n\t\t\tsubscriber(value)\n\t\t}\n\t}\n}\n","import type { AtomToken, TimelineUpdate } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { target } from \"../transaction\"\nimport type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineTransactionUpdate,\n} from \"./create-timeline\"\n\nexport const addAtomToTimeline = (\n\tatomToken: AtomToken<any>,\n\ttl: Timeline,\n\tstore: Store,\n): void => {\n\tconst atom = withdraw(atomToken, store)\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\tatom.subject.subscribe(`timeline`, (update) => {\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 =\n\t\t\tstore.transactionStatus.phase === `applying`\n\t\t\t\t? store.transactionStatus.key\n\t\t\t\t: null\n\t\tconst currentTransactionTime =\n\t\t\tstore.transactionStatus.phase === `applying`\n\t\t\t\t? store.transactionStatus.time\n\t\t\t\t: null\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\n\t\tif (tl.timeTraveling === null) {\n\t\t\tif (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {\n\t\t\t\tconst mostRecentUpdate: TimelineUpdate | undefined = tl.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 (\n\t\t\t\tcurrentTransactionKey &&\n\t\t\t\tstore.transactionStatus.phase === `applying`\n\t\t\t) {\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 atomUpdates = update.atomUpdates.filter((atomUpdate) => {\n\t\t\t\t\t\t\t\t\tconst core = target(store)\n\t\t\t\t\t\t\t\t\tconst atomOrFamilyKeys = core.timelineAtoms.getRelatedKeys(\n\t\t\t\t\t\t\t\t\t\ttl.key,\n\t\t\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\t\t\t\treturn atomOrFamilyKeys\n\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(key) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\tkey === atomUpdate.key ||\n\t\t\t\t\t\t\t\t\t\t\t\t\tkey === atomUpdate.family?.key,\n\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t: false\n\t\t\t\t\t\t\t\t})\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\tatomUpdates,\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 | 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 = {\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\tFamilyMetadata,\n\tStateUpdate,\n\tTimelineOptions,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionUpdate,\n\tƒn,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\nimport { addAtomToTimeline } from \"./add-atom-to-timeline\"\n\nexport type TimelineAtomUpdate = StateUpdate<unknown> & {\n\tkey: string\n\ttype: `atom_update`\n\ttimestamp: number\n\tfamily?: FamilyMetadata\n}\nexport type TimelineSelectorUpdate = {\n\tkey: string\n\ttype: `selector_update`\n\ttimestamp: number\n\tatomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[]\n}\nexport type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {\n\tkey: string\n\ttype: `transaction_update`\n\ttimestamp: number\n}\n\nexport type Timeline = {\n\ttype: `timeline`\n\tkey: string\n\tat: number\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n\ttimeTraveling: `into_future` | `into_past` | null\n\thistory: TimelineUpdate[]\n\tselectorTime: number | null\n\ttransactionKey: string | null\n\tinstall: (store: Store) => void\n\tsubject: Subject<\n\t\t| TimelineAtomUpdate\n\t\t| TimelineSelectorUpdate\n\t\t| TimelineTransactionUpdate\n\t\t| `redo`\n\t\t| `undo`\n\t>\n}\n\nexport function createTimeline(\n\toptions: TimelineOptions,\n\tstore: Store,\n\tdata?: Timeline,\n): TimelineToken {\n\tconst tl: Timeline = {\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\n\tconst core = target(store)\n\tfor (const tokenOrFamily of options.atoms) {\n\t\tconst timelineKey = core.timelineAtoms.getRelatedKey(tokenOrFamily.key)\n\t\tif (timelineKey) {\n\t\t\tstore.logger.error(\n\t\t\t\t`❌`,\n\t\t\t\t`timeline`,\n\t\t\t\toptions.key,\n\t\t\t\t`Failed to add atom \"${tokenOrFamily.key}\" because it already belongs to timeline \"${timelineKey}\"`,\n\t\t\t)\n\t\t\tcontinue\n\t\t}\n\t\tif (tokenOrFamily.type === `atom_family`) {\n\t\t\tconst family = tokenOrFamily\n\t\t\tfamily.subject.subscribe(`timeline:${options.key}`, (token) => {\n\t\t\t\t// if (!core.atoms.has(token.key)) {\n\t\t\t\taddAtomToTimeline(token, tl, store)\n\t\t\t\t// }\n\t\t\t})\n\t\t\tfor (const atom of core.atoms.values()) {\n\t\t\t\tif (atom.family?.key === family.key) {\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\tconst token = tokenOrFamily\n\t\t\tif (`family` in token && token.family) {\n\t\t\t\tconst familyTimelineKey = core.timelineAtoms.getRelatedKey(\n\t\t\t\t\ttoken.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 \"${token.key}\" because its family \"${token.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\taddAtomToTimeline(token, tl, store)\n\t\t}\n\t\tcore.timelineAtoms = core.timelineAtoms.set({\n\t\t\tatomKey: tokenOrFamily.key,\n\t\t\ttimelineKey: options.key,\n\t\t})\n\t}\n\n\tstore.timelines.set(options.key, tl)\n\tconst token: TimelineToken = {\n\t\tkey: options.key,\n\t\ttype: `timeline`,\n\t}\n\tstore.subject.timelineCreation.next(token)\n\treturn token\n}\n","import type { TimelineToken } from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport type { Store } from \"../store\"\n\nexport const timeTravel = (\n\tdirection: `backward` | `forward`,\n\ttoken: TimelineToken,\n\tstore: Store,\n): void => {\n\tconst action = direction === `forward` ? `redo` : `undo`\n\tstore.logger.info(\n\t\tdirection === `forward` ? `⏩` : `⏪`,\n\t\t`timeline`,\n\t\ttoken.key,\n\t\taction,\n\t)\n\n\tconst timelineData = store.timelines.get(token.key)\n\tif (!timelineData) {\n\t\tstore.logger.error(\n\t\t\t`🐞`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Failed to ${action}. This timeline has not been initialized.`,\n\t\t)\n\t\treturn\n\t}\n\n\tif (\n\t\t(direction === `forward` &&\n\t\t\ttimelineData.at === timelineData.history.length) ||\n\t\t(direction === `backward` && 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\tdirection === `forward` ? `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 =\n\t\tdirection === `forward` ? `into_future` : `into_past`\n\tif (direction === `backward`) {\n\t\t--timelineData.at\n\t}\n\n\tconst update = timelineData.history[timelineData.at]\n\tconst updateValues = (atomUpdate: any) => {\n\t\tconst { key, newValue, oldValue } = atomUpdate\n\t\tconst value = direction === `forward` ? newValue : oldValue\n\t\tsetState({ key, type: `atom` }, value, store)\n\t}\n\n\tswitch (update.type) {\n\t\tcase `atom_update`: {\n\t\t\tupdateValues(update)\n\t\t\tbreak\n\t\t}\n\t\tcase `selector_update`:\n\t\tcase `transaction_update`: {\n\t\t\tconst updates =\n\t\t\t\tdirection === `forward`\n\t\t\t\t\t? update.atomUpdates\n\t\t\t\t\t: [...update.atomUpdates].reverse()\n\t\t\tfor (const atomUpdate of updates) {\n\t\t\t\tupdateValues(atomUpdate)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif (direction === `forward`) {\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 type {\n\tAtomToken,\n\tReadonlySelectorToken,\n\tSelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTransactionToken,\n\tƒn,\n} from \"atom.io\"\n\nimport type { Atom } from \"../atom\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport { addAtomToTimeline } from \"../timeline\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport { target } from \"../transaction\"\nimport type { Store } from \"./store\"\n\nexport function withdraw<T>(\n\ttoken: AtomToken<T>,\n\tstore: Store,\n): Atom<T> | undefined\nexport function withdraw<T>(\n\ttoken: SelectorToken<T>,\n\tstore: Store,\n): Selector<T> | undefined\nexport function withdraw<T>(\n\ttoken: StateToken<T>,\n\tstore: Store,\n): Atom<T> | Selector<T> | undefined\nexport function withdraw<T>(\n\ttoken: ReadonlySelectorToken<T>,\n\tstore: Store,\n): ReadonlySelector<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: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Store,\n): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined\nexport function withdraw<T>(\n\ttoken: TimelineToken,\n\tstore: Store,\n): Timeline | undefined\nexport function withdraw<T>(\n\ttoken:\n\t\t| ReadonlySelectorToken<T>\n\t\t| StateToken<T>\n\t\t| TimelineToken\n\t\t| TransactionToken<T>,\n\tstore: Store,\n):\n\t| Atom<T>\n\t| ReadonlySelector<T>\n\t| Selector<T>\n\t| Timeline\n\t| Transaction<T extends ƒn ? T : never>\n\t| undefined {\n\tlet core = target(store)\n\tlet state =\n\t\tcore.atoms.get(token.key) ??\n\t\tcore.selectors.get(token.key) ??\n\t\tcore.readonlySelectors.get(token.key) ??\n\t\tcore.transactions.get(token.key) ??\n\t\tcore.timelines.get(token.key)\n\tif (state) {\n\t\treturn state\n\t}\n\tif (store.transactionStatus.phase === `applying`) {\n\t\tcore = store.transactionStatus.core\n\t\tstate =\n\t\t\tcore.atoms.get(token.key) ??\n\t\t\tcore.selectors.get(token.key) ??\n\t\t\tcore.readonlySelectors.get(token.key) ??\n\t\t\tcore.transactions.get(token.key) ??\n\t\t\tcore.timelines.get(token.key)\n\n\t\tif (state) {\n\t\t\tstore.logger.info(\n\t\t\t\t`🛠️`,\n\t\t\t\ttoken.type,\n\t\t\t\ttoken.key,\n\t\t\t\t`add ${token.type} \"${token.key}\"`,\n\t\t\t)\n\t\t\tswitch (state.type) {\n\t\t\t\tcase `atom`: {\n\t\t\t\t\tstore.atoms.set(token.key, state)\n\t\t\t\t\tstore.valueMap.set(token.key, state.default)\n\t\t\t\t\tconst stateKey = state.key\n\t\t\t\t\tconst familyKey = state.family?.key\n\t\t\t\t\tlet timelineKey = core.timelineAtoms.getRelatedKey(stateKey)\n\t\t\t\t\tif (timelineKey === undefined && typeof familyKey === `string`) {\n\t\t\t\t\t\ttimelineKey = core.timelineAtoms.getRelatedKey(familyKey)\n\t\t\t\t\t}\n\t\t\t\t\tconst timeline =\n\t\t\t\t\t\ttypeof timelineKey === `string`\n\t\t\t\t\t\t\t? store.timelines.get(timelineKey)\n\t\t\t\t\t\t\t: undefined\n\n\t\t\t\t\tif (timeline) {\n\t\t\t\t\t\taddAtomToTimeline(state, timeline, store)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase `selector`:\n\t\t\t\t\tcore.selectors.set(token.key, state)\n\t\t\t\t\tbreak\n\t\t\t\tcase `readonly_selector`:\n\t\t\t\t\tcore.readonlySelectors.set(token.key, state)\n\t\t\t\t\tbreak\n\t\t\t\tcase `transaction`:\n\t\t\t\t\tcore.transactions.set(token.key, state)\n\t\t\t\t\tbreak\n\t\t\t\tcase `timeline`:\n\t\t\t\t\tcore.timelines.set(token.key, state)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t\treturn state\n\t\t}\n\t}\n\treturn undefined\n}\n","import type {\n\tAtomToken,\n\tReadonlySelectorToken,\n\tSelectorToken,\n\tStateToken,\n} from \"atom.io\"\nimport type { Atom, ReadonlySelector, Selector, Store } from \"..\"\nimport { withdraw } from \"..\"\nimport { target } from \"../transaction\"\n\nexport function withdrawNewFamilyMember<T>(\n\ttoken: AtomToken<T>,\n\tstore: Store,\n): Atom<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: SelectorToken<T>,\n\tstore: Store,\n): Selector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadonlySelectorToken<T>,\n\tstore: Store,\n): ReadonlySelector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: StateToken<T>,\n\tstore: Store,\n): Atom<T> | Selector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Store,\n): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined\nexport function withdrawNewFamilyMember<T>(\n\ttoken:\n\t\t| AtomToken<T>\n\t\t| ReadonlySelectorToken<T>\n\t\t| SelectorToken<T>\n\t\t| StateToken<T>,\n\tstore: Store,\n): Atom<T> | ReadonlySelector<T> | Selector<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 core = target(store)\n\t\tconst family = core.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","import { Junction } from \"~/packages/rel8/junction/src\"\n\nimport type { Store } from \"../store\"\n\nexport const buildTransaction = (\n\tkey: string,\n\tparams: any[],\n\tstore: Store,\n): void => {\n\tstore.transactionStatus = {\n\t\tkey,\n\t\tphase: `building`,\n\t\ttime: Date.now(),\n\t\tcore: {\n\t\t\tatoms: new Map(store.atoms),\n\t\t\tatomsThatAreDefault: new Set(store.atomsThatAreDefault),\n\t\t\tfamilies: new Map(store.families),\n\t\t\toperation: { open: false },\n\t\t\treadonlySelectors: new Map(store.readonlySelectors),\n\t\t\ttimelines: new Map(store.timelines),\n\t\t\ttimelineAtoms: new Junction(store.timelineAtoms.toJSON()),\n\t\t\ttrackers: new Map(),\n\t\t\ttransactions: new Map(store.transactions),\n\t\t\tselectorAtoms: new Junction(store.selectorAtoms.toJSON()),\n\t\t\tselectorGraph: new Junction(store.selectorGraph.toJSON(), {\n\t\t\t\tmakeContentKey: (...keys) => keys.sort().join(`:`),\n\t\t\t}),\n\t\t\tselectors: new Map(store.selectors),\n\t\t\tvalueMap: new Map(store.valueMap),\n\t\t},\n\t\tatomUpdates: [],\n\t\tparams,\n\t\toutput: undefined,\n\t}\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\"\nimport { getState, setState } from \"atom.io\"\n\nimport { deposit } from \"../store\"\nimport type { Store, StoreCore } 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<ƒ>) => 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<ƒ>) => {\n\t\t\tbuildTransaction(options.key, params, store)\n\t\t\ttry {\n\t\t\t\tconst output = options.do(\n\t\t\t\t\t{\n\t\t\t\t\t\tget: (token) => getState(token, store),\n\t\t\t\t\t\tset: (token, value) => setState(token, value, store),\n\t\t\t\t\t},\n\t\t\t\t\t...params,\n\t\t\t\t)\n\t\t\t\tapplyTransaction(output, store)\n\t\t\t\treturn output\n\t\t\t} catch (thrown) {\n\t\t\t\tabortTransaction(store)\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 core = target(store)\n\tcore.transactions.set(newTransaction.key, newTransaction)\n\tconst token = deposit(newTransaction)\n\tstore.subject.transactionCreation.next(token)\n\treturn token\n}\n\nexport const target = (store: Store): StoreCore =>\n\tstore.transactionStatus.phase === `building`\n\t\t? store.transactionStatus.core\n\t\t: store\n","import type { AtomToken, TransactionUpdate, ƒn } from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport { withdraw } from \"../store\"\nimport type { Store } from \"../store\"\n\nexport const redoTransactionUpdate = <ƒ extends ƒn>(\n\tupdate: TransactionUpdate<ƒ>,\n\tstore: Store,\n): void => {\n\tstore.logger.info(`⏭️`, `transaction`, update.key, `Redo`)\n\tfor (const { key, newValue } of update.atomUpdates) {\n\t\tconst token: AtomToken<unknown> = { key, type: `atom` }\n\t\tconst state = withdraw(token, store)\n\t\tif (state === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${token.key}\" not found in this store. This is surprising, because we are navigating the history of the store.`,\n\t\t\t)\n\t\t}\n\t\tsetState(state, newValue, store)\n\t}\n}\n","import type { AtomToken, TransactionUpdate, ƒn } from \"atom.io\"\nimport { setState } from \"atom.io\"\n\nimport { withdraw } from \"../store\"\nimport type { Store } from \"../store\"\n\nexport const undoTransactionUpdate = <ƒ extends ƒn>(\n\tupdate: TransactionUpdate<ƒ>,\n\tstore: Store,\n): void => {\n\tstore.logger.info(\n\t\t`⏮️`,\n\t\t`transaction`,\n\t\tupdate.key,\n\t\t`Undoing transaction update`,\n\t\tupdate,\n\t)\n\tfor (const { key, oldValue } of update.atomUpdates) {\n\t\tconst token: AtomToken<unknown> = { key, type: `atom` }\n\t\tconst state = withdraw(token, store)\n\t\tif (state === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${token.key}\" not found in this store. This is surprising, because we are navigating the history of the store.`,\n\t\t\t)\n\t\t}\n\t\tsetState(state, oldValue, store)\n\t}\n}\n","import type { TransactionUpdate, ƒn } from \"atom.io\"\n\nimport type { StoreCore } from \"..\"\n\nexport * from \"./abort-transaction\"\nexport * from \"./apply-transaction\"\nexport * from \"./build-transaction\"\nexport * from \"./create-transaction\"\nexport * from \"./redo-transaction\"\nexport * from \"./undo-transaction\"\n\nexport const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const\nexport type TransactionPhase = (typeof TRANSACTION_PHASES)[number]\n\nexport type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {\n\tphase: `applying` | `building`\n\ttime: number\n\tcore: StoreCore\n}\nexport type TransactionIdle = {\n\tphase: `idle`\n}\nexport type TransactionStatus<ƒ extends ƒn> =\n\t| TransactionIdle\n\t| TransactionUpdateInProgress<ƒ>\n","import type { StateUpdate } from \"atom.io\"\nimport { Future } from \"./future\"\nimport type { Store } from \"./store\"\nimport type { Subject } from \"./subject\"\nimport { target } from \"./transaction\"\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\tstore: Store,\n): Future<T> | T {\n\tconst currentValue = target(store).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(store).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, store)\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\tstore.logger.error(`💥`, `state`, key, `rejected:`, thrown)\n\t\t\t\t}\n\t\t\t})\n\t\treturn future\n\t}\n\ttarget(store).valueMap.set(key, value)\n\treturn value\n}\n\nexport const readCachedValue = <T>(key: string, store: Store): T =>\n\ttarget(store).valueMap.get(key)\n\nexport const isValueCached = (key: string, store: Store): boolean =>\n\ttarget(store).valueMap.has(key)\n\nexport const evictCachedValue = (key: string, store: Store): void => {\n\tconst core = target(store)\n\tconst currentValue = core.valueMap.get(key)\n\tif (currentValue instanceof Future) {\n\t\tcurrentValue.cancel()\n\t}\n\tif (core.operation.open) {\n\t\tcore.operation.prev.set(key, currentValue)\n\t}\n\tcore.valueMap.delete(key)\n\tstore.logger.info(`🗑`, `state`, key, `evicted`)\n}\n","import type { MutableAtomOptions, MutableAtomToken } from \"atom.io\"\nimport { subscribe } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJson } from \"atom.io/json\"\n\nimport { createAtom } from \"../atom\"\nimport type { Store } from \"../store\"\nimport { target } from \"../transaction\"\nimport { Tracker } from \"./tracker\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtom<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n>(\n\toptions: MutableAtomOptions<Core, SerializableCore>,\n\tstore: Store,\n): MutableAtomToken<Core, SerializableCore> {\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 coreState = createAtom<Core>(options, undefined, store)\n\tnew Tracker(coreState, store)\n\tconst jsonState = selectJson(coreState, options, store)\n\tsubscribe(\n\t\tjsonState,\n\t\t() => {\n\t\t\tconst trackerHasBeenInitialized = target(store).trackers.has(coreState.key)\n\t\t\tif (!trackerHasBeenInitialized) {\n\t\t\t\tnew Tracker(coreState, store)\n\t\t\t}\n\t\t},\n\t\t`tracker-initializer:${store?.config.name}:${\n\t\t\tstore.transactionStatus.phase === `idle`\n\t\t\t\t? `main`\n\t\t\t\t: store.transactionStatus.key\n\t\t}`,\n\t)\n\treturn coreState as MutableAtomToken<Core, SerializableCore>\n}\n","import type { AtomToken, FamilyMetadata, MutableAtomToken } from \"atom.io\"\nimport { getState, setState, subscribe, subscribeToTimeline } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"..\"\nimport { createAtom, deleteAtom } from \"../atom\"\nimport { target } from \"../transaction\"\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): AtomToken<typeof this.Update | null> {\n\t\tconst latestUpdateStateKey = `*${mutableState.key}`\n\t\tdeleteAtom({ type: `atom`, key: latestUpdateStateKey }, store)\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 = createAtom<\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\n\t\treturn latestUpdateState\n\t}\n\n\tprivate unsubscribeFromInnerValue: (() => void) | null = null\n\tprivate observeCore(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tlatestUpdateState: AtomToken<typeof this.Update | null>,\n\t\tstore: Store,\n\t): void {\n\t\tconst originalInnerValue = getState(mutableState, store)\n\t\tthis.unsubscribeFromInnerValue = originalInnerValue.subscribe(\n\t\t\t`tracker:${store.config.name}:${\n\t\t\t\tstore.transactionStatus.phase === `idle`\n\t\t\t\t\t? `main`\n\t\t\t\t\t: store.transactionStatus.key\n\t\t\t}`,\n\t\t\t(update) => {\n\t\t\t\tconst unsubscribe = store.subject.operationStatus.subscribe(\n\t\t\t\t\tmutableState.key,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\tsetState(latestUpdateState, update, store)\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t},\n\t\t)\n\t\tsubscribe(\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\tthis.unsubscribeFromInnerValue = update.newValue.subscribe(\n\t\t\t\t\t\t`tracker:${store.config.name}:${\n\t\t\t\t\t\t\tstore.transactionStatus.phase === `idle`\n\t\t\t\t\t\t\t\t? `main`\n\t\t\t\t\t\t\t\t: store.transactionStatus.key\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t(update) => {\n\t\t\t\t\t\t\tconst unsubscribe = store.subject.operationStatus.subscribe(\n\t\t\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\t\tsetState(latestUpdateState, update, store)\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\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: AtomToken<typeof this.Update | null>,\n\t\tstore: Store,\n\t): void {\n\t\tsubscribe(\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)\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.subject.operationStatus.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\tconst updateNumber = 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\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: AtomToken<typeof this.Update | null>\n\n\tpublic constructor(\n\t\tmutableState: MutableAtomToken<Mutable, Json.Serializable>,\n\t\tstore: Store,\n\t) {\n\t\tthis.mutableState = mutableState\n\t\tthis.latestUpdateState = this.initializeState(mutableState, store)\n\t\tthis.observeCore(mutableState, this.latestUpdateState, store)\n\t\tthis.updateCore(mutableState, this.latestUpdateState, store)\n\t\tconst core = target(store)\n\t\tcore.trackers.set(mutableState.key, this)\n\t}\n}\n","import type { MutableAtomFamily, MutableAtomFamilyOptions } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { selectJsonFamily } from \"atom.io/json\"\n\nimport type { Store } from \"..\"\nimport { createAtomFamily } from \"..\"\nimport { FamilyTracker } from \"./tracker-family\"\nimport type { Transceiver } from \"./transceiver\"\n\nexport function createMutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends string,\n>(\n\toptions: MutableAtomFamilyOptions<Core, SerializableCore, Key>,\n\tstore: Store,\n): MutableAtomFamily<Core, SerializableCore, Key> {\n\tconst coreFamily = Object.assign(\n\t\tcreateAtomFamily<Core, Key>(options, store),\n\t\toptions,\n\t) as MutableAtomFamily<Core, SerializableCore, Key>\n\tselectJsonFamily(coreFamily, options)\n\tnew FamilyTracker(coreFamily, store)\n\treturn coreFamily\n}\n","import type { AtomFamily } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport { createAtomFamily } 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: AtomFamily<\n\t\ttypeof this.Update | null,\n\t\tFamilyMemberKey\n\t>\n\tpublic readonly findMutableState: AtomFamily<Core, FamilyMemberKey>\n\n\tpublic constructor(\n\t\tfindMutableState: AtomFamily<Core, FamilyMemberKey>,\n\t\tstore: Store,\n\t) {\n\t\tthis.findLatestUpdateState = createAtomFamily<\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\tAtomFamily,\n\tAtomFamilyOptions,\n\tAtomOptions,\n\tAtomToken,\n\tFamilyMetadata,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createAtom } from \"../atom\"\nimport { deposit, withdraw } from \"../store\"\nimport type { Store } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\n\nexport function createAtomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n\tstore: Store,\n): AtomFamily<T, K> {\n\tconst subject = new Subject<AtomToken<T>>()\n\tconst atomFamily = Object.assign(\n\t\t(key: K): AtomToken<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 = withdraw({ key: fullKey, type: `atom` }, store)\n\t\t\tlet token: AtomToken<any>\n\t\t\tif (existing) {\n\t\t\t\ttoken = deposit(existing)\n\t\t\t} else {\n\t\t\t\tconst individualOptions: AtomOptions<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\t// if (`toJson` in options && `fromJson` in options) {\n\t\t\t\t// \tindividualOptions.toJson = options.toJson\n\t\t\t\t// \tindividualOptions.fromJson\n\t\t\t\t// }\n\t\t\t\ttoken = createAtom<T>(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} as const,\n\t)\n\tconst core = target(store)\n\tcore.families.set(options.key, atomFamily)\n\treturn atomFamily\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 { createSelector } from \"../selector\"\nimport { type Store, deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\n\nexport function createReadonlySelectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n\tstore: Store,\n): ReadonlySelectorFamily<T, K> {\n\tconst core = target(store)\n\tconst subject = new Subject<ReadonlySelectorToken<T>>()\n\treturn Object.assign(\n\t\t(key: K): ReadonlySelectorToken<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 = core.readonlySelectors.get(fullKey)\n\t\t\tif (existing) {\n\t\t\t\treturn deposit(existing)\n\t\t\t}\n\t\t\treturn createSelector<T>(\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} as const,\n\t) as ReadonlySelectorFamily<T, K>\n}\n","import type { StateToken } from \"atom.io\"\n\nimport type { Store } from \"./store\"\nimport { target } from \"./transaction\"\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: StateToken<any>\n\t }\n\nexport const openOperation = (\n\ttoken: StateToken<any>,\n\tstore: Store,\n): `rejection` | undefined => {\n\tconst core = target(store)\n\tif (core.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 \"${core.operation.token.key}\"`,\n\t\t)\n\t\treturn `rejection`\n\t}\n\tcore.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.transactionStatus.phase === `idle`\n\t\t\t\t? ``\n\t\t\t\t: ` ${store.transactionStatus.phase} \"${store.transactionStatus.key}\"`\n\t\t}`,\n\t)\n}\nexport const closeOperation = (store: Store): void => {\n\tconst core = target(store)\n\tif (core.operation.open) {\n\t\tstore.logger.info(\n\t\t\t`🔴`,\n\t\t\tcore.operation.token.type,\n\t\t\tcore.operation.token.key,\n\t\t\t`operation done in store \"${store.config.name}\"`,\n\t\t)\n\t}\n\tcore.operation = { open: false }\n\tstore.subject.operationStatus.next(core.operation)\n}\n\nexport const isDone = (key: string, store: Store): boolean => {\n\tconst core = target(store)\n\tif (!core.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 core.operation.done.has(key)\n}\nexport const markDone = (key: string, store: Store): void => {\n\tconst core = target(store)\n\tif (!core.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\tcore.operation.done.add(key)\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 { Atom } from \"./atom\"\nimport { isValueCached, readCachedValue } from \"./caching\"\nimport type { ReadonlySelector, Selector } from \"./selector\"\nimport type { Store } from \"./store\"\n\nexport const readOrComputeValue = <T>(\n\tstate: Atom<T> | ReadonlySelector<T> | Selector<T>,\n\tstore: Store,\n): T => {\n\tif (isValueCached(state.key, store)) {\n\t\tstore.logger.info(`📖`, state.type, state.key, `reading cached value`)\n\t\treturn readCachedValue(state.key, store)\n\t}\n\tif (state.type !== `atom`) {\n\t\tstore.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\tstore.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 { JsonInterface } from \"atom.io/json\"\n\nimport type { Atom } from \"../atom\"\nimport { Tracker } from \"../mutable\"\nimport type { Store, StoreCore } from \"../store\"\n\nexport function copyMutableIfNeeded<T>(\n\tatom: Atom<T>,\n\ttransform: JsonInterface<T>,\n\torigin: Store,\n\ttarget: StoreCore,\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 copiedValue = transform.fromJson(transform.toJson(originValue))\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 type { AtomFamily } from \"atom.io\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\nimport { readOrComputeValue } from \"..\"\nimport type { Store, StoreCore } from \"..\"\nimport type { Atom } from \"../atom\"\nimport { copyMutableIfNeeded } from \"./copy-mutable-if-needed\"\n\nexport function copyMutableIfWithinTransaction<T>(\n\toldValue: T,\n\tatom: Atom<T> | (Atom<T> & JsonInterface<T, Json.Serializable>),\n\tstore: Store,\n): T {\n\tif (\n\t\tstore.transactionStatus.phase === `building` ||\n\t\tstore.transactionStatus.phase === `applying`\n\t) {\n\t\tif (`toJson` in atom && `fromJson` in atom) {\n\t\t\tconst copiedValue = copyMutableIfNeeded(\n\t\t\t\tatom,\n\t\t\t\tatom,\n\t\t\t\tstore,\n\t\t\t\tstore.transactionStatus.core,\n\t\t\t)\n\t\t\treturn copiedValue\n\t\t}\n\t\tif (`family` in atom) {\n\t\t\tconst family = store.transactionStatus.core.families.get(atom.family.key)\n\t\t\tif (family && family.type === `atom_family`) {\n\t\t\t\tconst result = copyMutableFamilyMemberWithinTransaction<T>(\n\t\t\t\t\tatom,\n\t\t\t\t\tfamily,\n\t\t\t\t\tstore,\n\t\t\t\t\tstore.transactionStatus.core,\n\t\t\t\t)\n\t\t\t\tif (result) {\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn oldValue\n}\n\nexport function copyMutableFamilyMemberWithinTransaction<T>(\n\tatom: Atom<T>,\n\tfamily:\n\t\t| AtomFamily<T, any>\n\t\t| (AtomFamily<T, any> & JsonInterface<T, Json.Serializable>),\n\torigin: Store,\n\ttarget: StoreCore,\n): T | null {\n\tif (`toJson` in family && `fromJson` in family) {\n\t\tconst copyCreated = copyMutableIfNeeded(atom, family, origin, target)\n\t\treturn copyCreated\n\t}\n\treturn null\n}\n","import type { StateUpdate } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\n\nimport type { Atom } from \"../atom\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\n\nexport const emitUpdate = <T>(\n\tstate: Atom<T> | ReadonlySelector<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 \"../atom\"\nimport { evictCachedValue } from \"../caching\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { target } from \"../transaction\"\n\nexport const evictDownStream = <T>(atom: Atom<T>, store: Store): void => {\n\tconst core = target(store)\n\tconst downstreamKeys = core.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 (core.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`[ ${[...core.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 \"../atom\"\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, unless they're not equal by reference\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\tif (store.transactionStatus.phase !== `building`) {\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\tstore.transactionStatus.atomUpdates.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 \"../atom\"\nimport { isAtomDefault, markAtomAsNotDefault } from \"../atom\"\nimport { cacheValue } from \"../caching\"\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\tstore: Store,\n): void => {\n\tconst oldValue = readOrComputeValue(atom, store)\n\tlet newValue = copyMutableIfWithinTransaction(oldValue, atom, store)\n\tnewValue = become(next)(newValue)\n\tstore.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)\n\tnewValue = cacheValue(atom.key, newValue, atom.subject, store)\n\tif (isAtomDefault(atom.key, store)) {\n\t\tmarkAtomAsNotDefault(atom.key, store)\n\t}\n\tmarkDone(atom.key, store)\n\tevictDownStream(atom, store)\n\tconst update = { oldValue, newValue }\n\tif (store.transactionStatus.phase !== `building`) {\n\t\temitUpdate(atom, update, store)\n\t} else {\n\t\tstowUpdate(atom, update, store)\n\t}\n}\n","import type { Atom } from \"../atom\"\nimport type { Selector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { setAtom } from \"./set-atom\"\n\nexport const setAtomOrSelector = <T>(\n\tstate: Atom<T> | Selector<T>,\n\tvalue: T | ((oldValue: T) => T),\n\tstore: Store,\n): void => {\n\tif (state.type === `selector`) {\n\t\tstate.set(value)\n\t} else {\n\t\tsetAtom(state, value, store)\n\t}\n}\n","import type { Store } from \"./store\"\nimport { target } from \"./transaction\"\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\ttarget(store).atoms.has(key)\nexport const isSelectorKey = (\n\tkey: string,\n\tstore: Store,\n): key is SelectorKey<unknown> => target(store).selectors.has(key)\nexport const isReadonlySelectorKey = (\n\tkey: string,\n\tstore: Store,\n): key is ReadonlySelectorKey<unknown> =>\n\ttarget(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 type { Store } from \"../store\"\nimport { target } from \"../transaction\"\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 = target(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 { 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\tselectorKey: string,\n\tstore: Store,\n): AtomKey<unknown>[] => {\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, StateToken } from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport { target } from \"../transaction\"\nimport { traceSelectorAtoms } from \"./trace-selector-atoms\"\n\nexport const updateSelectorAtoms = (\n\tselectorKey: string,\n\tdependency: ReadonlySelectorToken<unknown> | StateToken<unknown>,\n\tstore: Store,\n): void => {\n\tconst core = target(store)\n\tif (dependency.type === `atom`) {\n\t\tcore.selectorAtoms = core.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\tcore.selectorAtoms = core.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 { Transactors } from \"atom.io\"\n\nimport { readOrComputeValue } from \"../read-or-compute-value\"\nimport { setAtomOrSelector } from \"../set-state\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { target } from \"../transaction/create-transaction\"\nimport { updateSelectorAtoms } from \"./update-selector-atoms\"\n\nexport const registerSelector = (\n\tselectorKey: string,\n\tstore: Store,\n): Transactors => ({\n\tget: (dependency) => {\n\t\tconst core = target(store)\n\t\tconst alreadyRegistered = core.selectorGraph\n\t\t\t.getRelationEntries({ downstreamSelectorKey: selectorKey })\n\t\t\t.some(([_, { source }]) => source === dependency.key)\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\tif (!alreadyRegistered) {\n\t\t\tcore.selectorGraph = core.selectorGraph.set(\n\t\t\t\t{\n\t\t\t\t\tupstreamSelectorKey: dependency.key,\n\t\t\t\t\tdownstreamSelectorKey: selectorKey,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tsource: dependency.key,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\tupdateSelectorAtoms(selectorKey, dependency, store)\n\t\treturn dependencyValue\n\t},\n\tset: (stateToken, newValue) => {\n\t\tconst state = withdraw(stateToken, store)\n\t\tif (state === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`State \"${stateToken.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})\n","import type { FamilyMetadata, SelectorOptions, SelectorToken } from \"atom.io\"\n\nimport { cacheValue } from \"../caching\"\nimport { markDone } from \"../operation\"\nimport { become } from \"../set-state/become\"\nimport type { Store, StoreCore } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { Selector } from \"./create-selector\"\nimport { createSelector } from \"./create-selector\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadWriteSelector = <T>(\n\toptions: SelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n\tcore: StoreCore,\n): SelectorToken<T> => {\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\n\tconst { get, set } = registerSelector(options.key, store)\n\tconst getSelf = () => {\n\t\tconst value = options.get({ get })\n\t\tcacheValue(options.key, value, subject, 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\t// store.logger.info(`📝 set \"${options.key}\" (`, oldValue, `->`, newValue, `)`)\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 (store.transactionStatus.phase === `idle`) {\n\t\t\tsubject.next({ newValue, oldValue })\n\t\t}\n\t\toptions.set({ get, set }, newValue)\n\t}\n\tconst mySelector: Selector<T> = {\n\t\t...options,\n\t\tsubject,\n\t\tinstall: (s: Store) => createSelector(options, family, s),\n\t\tget: getSelf,\n\t\tset: setSelf,\n\t\ttype: `selector`,\n\t\t...(family && { family }),\n\t}\n\tcore.selectors.set(options.key, mySelector)\n\tconst initialValue = getSelf()\n\tstore.logger.info(`✨`, mySelector.type, mySelector.key, `=`, initialValue)\n\tconst token: SelectorToken<T> = {\n\t\tkey: options.key,\n\t\ttype: `selector`,\n\t}\n\tif (family) {\n\t\ttoken.family = family\n\t}\n\tstore.subject.selectorCreation.next(token)\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorOptions,\n\tReadonlySelectorToken,\n} from \"atom.io\"\n\nimport { cacheValue } from \"../caching\"\nimport type { Store, StoreCore } from \"../store\"\nimport { Subject } from \"../subject\"\nimport type { ReadonlySelector } from \"./create-selector\"\nimport { createSelector } from \"./create-selector\"\nimport { registerSelector } from \"./register-selector\"\n\nexport const createReadonlySelector = <T>(\n\toptions: ReadonlySelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n\tcore: StoreCore,\n): ReadonlySelectorToken<T> => {\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\n\tconst { get } = registerSelector(options.key, store)\n\tconst getSelf = () => {\n\t\tconst value = options.get({ get })\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) => createSelector(options, family, s),\n\t\tget: getSelf,\n\t\ttype: `readonly_selector`,\n\t\t...(family && { family }),\n\t}\n\tcore.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.subject.selectorCreation.next(token)\n\treturn token\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorOptions,\n\tReadonlySelectorToken,\n\tSelectorOptions,\n\tSelectorToken,\n} from \"atom.io\"\n\nimport type { Store } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\nimport { createReadWriteSelector } from \"./create-read-write-selector\"\nimport { createReadonlySelector } from \"./create-readonly-selector\"\n\nexport type Selector<T> = {\n\tkey: string\n\ttype: `selector`\n\tfamily?: FamilyMetadata\n\tinstall: (store: Store) => void\n\tsubject: Subject<{ newValue: T; oldValue: T }>\n\tget: () => T\n\tset: (newValue: T | ((oldValue: T) => T)) => void\n}\nexport type ReadonlySelector<T> = {\n\tkey: string\n\ttype: `readonly_selector`\n\tfamily?: FamilyMetadata\n\tinstall: (store: Store) => void\n\tsubject: Subject<{ newValue: T; oldValue: T }>\n\tget: () => T\n}\n\nexport function createSelector<T>(\n\toptions: SelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): SelectorToken<T>\nexport function createSelector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): ReadonlySelectorToken<T>\nexport function createSelector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n\tfamily: FamilyMetadata | undefined,\n\tstore: Store,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\tconst core = target(store)\n\tconst existingWritable = core.selectors.get(options.key)\n\tconst existingReadonly = core.readonlySelectors.get(options.key)\n\n\tif (existingWritable || existingReadonly) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\texistingReadonly ? `readonly_selector` : `selector`,\n\t\t\toptions.key,\n\t\t\t`Tried to create selector, but it already exists in the store. (Ignore if you are in development using hot module replacement.)`,\n\t\t)\n\t}\n\n\tif (`set` in options) {\n\t\treturn createReadWriteSelector(options, family, store, core)\n\t}\n\treturn createReadonlySelector(options, family, store, core)\n}\n","import type { ReadonlySelectorToken, SelectorToken } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { target } from \"..\"\n\nexport function deleteSelector(\n\tselectorToken: ReadonlySelectorToken<unknown> | SelectorToken<unknown>,\n\tstore: Store,\n): void {\n\tconst core = target(store)\n\tconst { key } = selectorToken\n\tswitch (selectorToken.type) {\n\t\tcase `selector`:\n\t\t\tcore.selectors.delete(key)\n\t\t\tbreak\n\t\tcase `readonly_selector`:\n\t\t\tcore.readonlySelectors.delete(key)\n\t\t\tbreak\n\t}\n\tcore.valueMap.delete(key)\n\tcore.selectorAtoms.delete(key)\n\tconst downstreamTokens = core.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\tcore.selectors.get(downstreamSelectorKey) ??\n\t\t\t\tcore.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\tcore.selectorGraph.delete(key)\n\tstore.logger.info(`🔥`, selectorToken.type, `${key}`, `deleted`)\n}\n","import type {\n\tFamilyMetadata,\n\tReadonlySelectorFamily,\n\tReadonlySelectorFamilyOptions,\n\tSelectorFamily,\n\tSelectorFamilyOptions,\n\tSelectorToken,\n} from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { createSelector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\nimport { createReadonlySelectorFamily } from \"./create-readonly-selector-family\"\n\nexport function createSelectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n\tstore: Store,\n): SelectorFamily<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: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n\tstore: Store,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\tconst isReadonly = !(`set` in options)\n\n\tif (isReadonly) {\n\t\treturn createReadonlySelectorFamily(options, store)\n\t}\n\tconst core = target(store)\n\tconst subject = new Subject<SelectorToken<T>>()\n\n\tconst selectorFamily = Object.assign(\n\t\t(key: K): SelectorToken<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 = core.selectors.get(fullKey)\n\t\t\tif (existing) {\n\t\t\t\treturn deposit(existing)\n\t\t\t}\n\t\t\tconst token = createSelector<T>(\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} as const,\n\t) as SelectorFamily<T, K>\n\tcore.families.set(options.key, selectorFamily)\n\treturn selectorFamily\n}\n","import type { MutableAtomFamily, SelectorFamily } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { target } from \"../transaction\"\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): SelectorFamily<SerializableCore, Key> => {\n\tconst core = target(store)\n\tconst key = `${mutableAtomFamily.key}:JSON`\n\tconst jsonFamily: SelectorFamily<SerializableCore, Key> = core.families.get(\n\t\tkey,\n\t) as SelectorFamily<SerializableCore, Key>\n\treturn jsonFamily\n}\n","import type { MutableAtomToken, SelectorToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { Transceiver } from \"./transceiver\"\n\nexport const getJsonToken = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): SelectorToken<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: SelectorToken<SerializableCore> = { type: `selector`, key }\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 { AtomToken, MutableAtomToken } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport type { Signal, Transceiver } from \"./transceiver\"\n\nexport const getUpdateToken = <\n\tCore extends Transceiver<Json.Serializable>,\n\tSerializableCore extends Json.Serializable,\n>(\n\tmutableAtomToken: MutableAtomToken<Core, SerializableCore>,\n): AtomToken<Signal<Core>> => {\n\tconst key = `*${mutableAtomToken.key}`\n\tconst updateToken: AtomToken<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 { AtomToken, MutableAtomToken } from \"atom.io\"\n\nexport function isAtomTokenMutable(\n\ttoken: AtomToken<any>,\n): token is MutableAtomToken<any, any> {\n\treturn token.key.endsWith(`::mutable`)\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 { Atom } from \"../atom\"\n\nexport * from \"./create-mutable-atom\"\nexport * from \"./create-mutable-atom-family\"\nexport * from \"./get-json-family\"\nexport * from \"./get-json-token\"\nexport * from \"./get-update-token\"\nexport * from \"./is-atom-token-mutable\"\nexport * from \"./tracker\"\nexport * from \"./tracker-family\"\nexport * from \"./transceiver\"\n\nexport interface MutableAtom<T> extends Atom<T> {\n\tmutable: true\n}\n\nexport const isAtomMutable = <T>(atom: Atom<T>): atom is MutableAtom<T> =>\n\t`isMutable` in atom\n","import { traceAllSelectorAtoms } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { target } from \"../transaction\"\n\nexport const isAtomDefault = (key: string, store: Store): boolean => {\n\tconst core = target(store)\n\treturn core.atomsThatAreDefault.has(key)\n}\n\nexport const markAtomAsDefault = (key: string, store: Store): void => {\n\tconst core = target(store)\n\tcore.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key)\n}\n\nexport const markAtomAsNotDefault = (key: string, store: Store): void => {\n\tconst core = target(store)\n\tcore.atomsThatAreDefault = new Set(target(store).atomsThatAreDefault)\n\tcore.atomsThatAreDefault.delete(key)\n}\n\nexport const isSelectorDefault = (key: string, store: Store): boolean => {\n\tconst rootKeys = traceAllSelectorAtoms(key, store)\n\treturn rootKeys.every((rootKey) => isAtomDefault(rootKey, store))\n}\n","import type { AtomToken } from \"atom.io\"\n\nimport type { Store } from \"..\"\nimport { deleteSelector, target } from \"..\"\n\nexport function deleteAtom(atomToken: AtomToken<unknown>, store: Store): void {\n\tconst core = target(store)\n\tconst { key } = atomToken\n\tconst atom = core.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\tcore.atoms.delete(key)\n\tcore.valueMap.delete(key)\n\tconst selectorKeys = core.selectorAtoms.getRelatedKeys(key)\n\tif (selectorKeys) {\n\t\tfor (const selectorKey of selectorKeys) {\n\t\t\tconst token =\n\t\t\t\tcore.selectors.get(selectorKey) ??\n\t\t\t\tcore.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\tcore.selectorAtoms.delete(key)\n\tcore.atomsThatAreDefault.delete(key)\n\tcore.timelineAtoms.delete(key)\n\tstore.logger.info(`🔥`, `atom`, `${key}`, `deleted`)\n}\n","import type { ReadonlySelectorToken, StateToken } from \"atom.io\"\n\nimport type { Store } from \"./store\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nfunction prettyPrintTokenType(\n\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n) {\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(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Store,\n\t) {\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 { Atom } from \"../atom\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { target } from \"../transaction\"\n\nexport const recallState = <T>(\n\tstate: Atom<T> | ReadonlySelector<T> | Selector<T>,\n\tstore: Store,\n): T => {\n\tconst core = target(store)\n\tif (!core.operation.open) {\n\t\tstore.logger.warn(\n\t\t\t`🐞`,\n\t\t\tstate.type,\n\t\t\tstate.key,\n\t\t\t`recall called outside of an operation. This is probably a bug.`,\n\t\t)\n\t\treturn core.valueMap.get(state.key)\n\t}\n\treturn core.operation.prev.get(state.key)\n}\n","import { readOrComputeValue } from \"../read-or-compute-value\"\nimport type { ReadonlySelector, Selector } from \"../selector\"\nimport { traceAllSelectorAtoms } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { recallState } from \"./recall-state\"\n\nexport const subscribeToRootAtoms = <T>(\n\tstate: ReadonlySelector<T> | Selector<T>,\n\tstore: Store,\n): (() => void)[] | null => {\n\tconst dependencySubscriptions =\n\t\t`default` in state\n\t\t\t? null\n\t\t\t: traceAllSelectorAtoms(state.key, store).map((atomKey) => {\n\t\t\t\t\tconst atom = store.atoms.get(atomKey)\n\t\t\t\t\tif (atom === undefined) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Atom \"${atomKey}\", a dependency of selector \"${state.key}\", not found in store \"${store.config.name}\".`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\treturn atom.subject.subscribe(\n\t\t\t\t\t\t`${state.type}:${state.key}`,\n\t\t\t\t\t\t(atomChange) => {\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\tstate.type,\n\t\t\t\t\t\t\t\tstate.key,\n\t\t\t\t\t\t\t\t`root`,\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\t`went`,\n\t\t\t\t\t\t\t\tatomChange.oldValue,\n\t\t\t\t\t\t\t\t`->`,\n\t\t\t\t\t\t\t\tatomChange.newValue,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tconst oldValue = recallState(state, store)\n\t\t\t\t\t\t\t// ❌ this retrieves a stale cached value when applying a transaction on the server\n\t\t\t\t\t\t\tconst newValue = readOrComputeValue(state, store)\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\tstate.type,\n\t\t\t\t\t\t\t\tstate.key,\n\t\t\t\t\t\t\t\t`went`,\n\t\t\t\t\t\t\t\toldValue,\n\t\t\t\t\t\t\t\t`->`,\n\t\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tstate.subject.next({ newValue, oldValue })\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t })\n\treturn dependencySubscriptions\n}\n"]}
|