atom.io 0.6.9 â 0.7.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/README.md +21 -2
- package/dist/index.d.mts +34 -421
- package/dist/index.d.ts +34 -421
- package/dist/index.js +248 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +209 -4
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +342 -0
- package/internal/dist/index.d.ts +342 -0
- package/internal/dist/index.js +1873 -0
- package/internal/dist/index.js.map +1 -0
- package/internal/dist/index.mjs +1798 -0
- package/internal/dist/index.mjs.map +1 -0
- package/internal/package.json +15 -0
- package/internal/src/atom/create-atom.ts +75 -0
- package/internal/src/atom/delete-atom.ts +10 -0
- package/internal/src/atom/index.ts +3 -0
- package/internal/src/atom/is-default.ts +37 -0
- package/internal/src/caching.ts +21 -0
- package/internal/src/families/create-atom-family.ts +59 -0
- package/internal/src/families/create-readonly-selector-family.ts +45 -0
- package/internal/src/families/create-selector-family.ts +67 -0
- package/internal/src/families/index.ts +3 -0
- package/internal/src/get-state-internal.ts +23 -0
- package/internal/src/index.ts +13 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +25 -0
- package/internal/src/mutable/create-mutable-atom.ts +49 -0
- package/internal/src/mutable/get-json-token.ts +22 -0
- package/internal/src/mutable/get-update-token.ts +20 -0
- package/internal/src/mutable/index.ts +17 -0
- package/internal/src/mutable/is-atom-token-mutable.ts +7 -0
- package/internal/src/mutable/tracker-family.ts +61 -0
- package/internal/src/mutable/tracker.ts +164 -0
- package/internal/src/mutable/transceiver.ts +110 -0
- package/internal/src/operation.ts +68 -0
- package/internal/src/selector/create-read-write-selector.ts +65 -0
- package/internal/src/selector/create-readonly-selector.ts +49 -0
- package/internal/src/selector/create-selector.ts +65 -0
- package/internal/src/selector/index.ts +5 -0
- package/internal/src/selector/lookup-selector-sources.ts +20 -0
- package/internal/src/selector/register-selector.ts +61 -0
- package/internal/src/selector/trace-selector-atoms.ts +45 -0
- package/internal/src/selector/update-selector-atoms.ts +34 -0
- package/internal/src/set-state/become.ts +10 -0
- package/internal/src/set-state/copy-mutable-if-needed.ts +23 -0
- package/internal/src/set-state/copy-mutable-in-transaction.ts +59 -0
- package/internal/src/set-state/copy-mutable-into-new-store.ts +34 -0
- package/internal/src/set-state/emit-update.ts +23 -0
- package/internal/src/set-state/evict-downstream.ts +39 -0
- package/internal/src/set-state/index.ts +2 -0
- package/internal/src/set-state/set-atom-state.ts +38 -0
- package/internal/src/set-state/set-selector-state.ts +19 -0
- package/internal/src/set-state/set-state-internal.ts +18 -0
- package/internal/src/set-state/stow-update.ts +42 -0
- package/internal/src/store/deposit.ts +43 -0
- package/internal/src/store/index.ts +5 -0
- package/internal/src/store/lookup.ts +26 -0
- package/internal/src/store/store.ts +154 -0
- package/internal/src/store/withdraw-new-family-member.ts +53 -0
- package/internal/src/store/withdraw.ts +113 -0
- package/internal/src/subject.ts +21 -0
- package/internal/src/subscribe/index.ts +1 -0
- package/internal/src/subscribe/recall-state.ts +19 -0
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +47 -0
- package/internal/src/timeline/add-atom-to-timeline.ts +189 -0
- package/internal/src/timeline/index.ts +3 -0
- package/internal/src/timeline/time-travel-internal.ts +91 -0
- package/internal/src/timeline/timeline-internal.ts +115 -0
- package/internal/src/transaction/abort-transaction.ts +12 -0
- package/internal/src/transaction/apply-transaction.ts +64 -0
- package/internal/src/transaction/build-transaction.ts +39 -0
- package/internal/src/transaction/index.ts +26 -0
- package/internal/src/transaction/redo-transaction.ts +22 -0
- package/internal/src/transaction/transaction-internal.ts +64 -0
- package/internal/src/transaction/undo-transaction.ts +22 -0
- package/introspection/dist/index.d.mts +3 -197
- package/introspection/dist/index.d.ts +3 -197
- package/introspection/dist/index.js +329 -4
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +310 -4
- package/introspection/dist/index.mjs.map +1 -1
- package/introspection/src/attach-atom-index.ts +84 -0
- package/introspection/src/attach-introspection-states.ts +38 -0
- package/introspection/src/attach-selector-index.ts +90 -0
- package/introspection/src/attach-timeline-family.ts +59 -0
- package/introspection/src/attach-timeline-index.ts +38 -0
- package/introspection/src/attach-transaction-index.ts +40 -0
- package/introspection/src/attach-transaction-logs.ts +43 -0
- package/introspection/src/index.ts +20 -0
- package/json/dist/index.d.mts +10 -2
- package/json/dist/index.d.ts +10 -2
- package/json/dist/index.js +83 -26
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs +74 -3
- package/json/dist/index.mjs.map +1 -1
- package/json/src/index.ts +5 -0
- package/json/src/select-json-family.ts +35 -0
- package/json/src/select-json.ts +22 -0
- package/package.json +103 -63
- package/react/dist/index.d.mts +9 -17
- package/react/dist/index.d.ts +9 -17
- package/react/dist/index.js +44 -27
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +24 -4
- package/react/dist/index.mjs.map +1 -1
- package/react/src/index.ts +2 -0
- package/react/src/store-context.tsx +12 -0
- package/react/src/store-hooks.ts +36 -0
- package/react-devtools/dist/index.css +50 -1
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +104 -71
- package/react-devtools/dist/index.d.ts +104 -71
- package/react-devtools/dist/index.js +2806 -44
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +2775 -10
- package/react-devtools/dist/index.mjs.map +1 -1
- package/react-devtools/src/AtomIODevtools.tsx +109 -0
- package/react-devtools/src/Button.tsx +23 -0
- package/react-devtools/src/StateEditor.tsx +75 -0
- package/react-devtools/src/StateIndex.tsx +159 -0
- package/react-devtools/src/TimelineIndex.tsx +88 -0
- package/react-devtools/src/TransactionIndex.tsx +70 -0
- package/react-devtools/src/Updates.tsx +150 -0
- package/react-devtools/src/devtools.scss +310 -0
- package/react-devtools/src/index.ts +72 -0
- package/realtime-react/dist/index.d.mts +8 -22
- package/realtime-react/dist/index.d.ts +8 -22
- package/realtime-react/dist/index.js +87 -32
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs +62 -6
- package/realtime-react/dist/index.mjs.map +1 -1
- package/realtime-react/src/index.ts +7 -0
- package/realtime-react/src/realtime-context.tsx +29 -0
- package/realtime-react/src/use-pull-family-member.ts +15 -0
- package/realtime-react/src/use-pull-mutable-family-member.ts +20 -0
- package/realtime-react/src/use-pull-mutable.ts +17 -0
- package/realtime-react/src/use-pull.ts +15 -0
- package/realtime-react/src/use-push.ts +19 -0
- package/realtime-react/src/use-server-action.ts +18 -0
- package/realtime-testing/dist/index.d.mts +49 -0
- package/realtime-testing/dist/index.d.ts +49 -0
- package/realtime-testing/dist/index.js +147 -0
- package/realtime-testing/dist/index.js.map +1 -0
- package/realtime-testing/dist/index.mjs +116 -0
- package/realtime-testing/dist/index.mjs.map +1 -0
- package/realtime-testing/src/index.ts +1 -0
- package/realtime-testing/src/setup-realtime-test.tsx +161 -0
- package/src/atom.ts +64 -9
- package/src/index.ts +36 -32
- package/src/logger.ts +3 -3
- package/src/selector.ts +3 -3
- package/src/silo.ts +29 -20
- package/src/subscribe.ts +3 -3
- package/src/timeline.ts +2 -2
- package/transceivers/set-rtx/dist/index.d.mts +39 -0
- package/transceivers/set-rtx/dist/index.d.ts +39 -0
- package/transceivers/set-rtx/dist/index.js +213 -0
- package/transceivers/set-rtx/dist/index.js.map +1 -0
- package/transceivers/set-rtx/dist/index.mjs +211 -0
- package/transceivers/set-rtx/dist/index.mjs.map +1 -0
- package/{realtime â transceivers/set-rtx}/package.json +1 -1
- package/transceivers/set-rtx/src/index.ts +1 -0
- package/transceivers/set-rtx/src/set-rtx.ts +242 -0
- package/realtime/dist/index.d.mts +0 -23
- package/realtime/dist/index.d.ts +0 -23
- package/realtime/dist/index.js +0 -32
- package/realtime/dist/index.js.map +0 -1
- package/realtime/dist/index.mjs +0 -7
- package/realtime/dist/index.mjs.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../internal/src/index.ts","../internal/src/store/store.ts","../../rel8/junction/src/junction.ts","../../anvl/src/function/index.ts","../../anvl/src/array/index.ts","../../anvl/src/nullish/index.ts","../../anvl/src/object/refinement.ts","../../anvl/src/object/access.ts","../../anvl/src/object/entries.ts","../../anvl/src/object/mapObject.ts","../../anvl/reactivity/subject.ts","../internal/src/store/deposit.ts","../internal/src/transaction/abort-transaction.ts","../internal/src/transaction/apply-transaction.ts","../internal/src/transaction/build-transaction.ts","../internal/src/transaction/transaction-internal.ts","../internal/src/transaction/redo-transaction.ts","../internal/src/transaction/undo-transaction.ts","../internal/src/transaction/index.ts","../internal/src/store/lookup.ts","../internal/src/timeline/add-atom-to-timeline.ts","../internal/src/timeline/time-travel-internal.ts","../internal/src/timeline/timeline-internal.ts","../internal/src/store/withdraw.ts","../internal/src/caching.ts","../internal/src/selector/lookup-selector-sources.ts","../internal/src/get-state-internal.ts","../internal/src/operation.ts","../internal/src/set-state/emit-update.ts","../internal/src/set-state/evict-downstream.ts","../internal/src/set-state/stow-update.ts","../internal/src/set-state/set-atom-state.ts","../internal/src/set-state/set-selector-state.ts","../internal/src/set-state/set-state-internal.ts","../internal/src/selector/trace-selector-atoms.ts","../internal/src/selector/update-selector-atoms.ts","../internal/src/selector/register-selector.ts","../internal/src/selector/create-read-write-selector.ts","../internal/src/selector/create-readonly-selector.ts","../internal/src/selector/selector-internal.ts","../internal/src/atom/is-default.ts","../internal/src/atom/atom-internal.ts","../../anvl/src/json/index.ts","../internal/src/families/atom-family-internal.ts","../internal/src/families/readonly-selector-family-internal.ts","../internal/src/families/selector-family-internal.ts","../internal/src/subscribe/recall-state.ts","../internal/src/subscribe/subscribe-to-root-atoms.ts","../../anvl/src/string/capitalize.ts","../src/atom.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/index.ts"],"names":["src_exports","__export","IMPLICIT","Store","Subject","TRANSACTION_PHASES","abortTransaction","addAtomToTimeline","applyTransaction","atomFamily__INTERNAL","atom__INTERNAL","buildTransaction","cacheValue","clearStore","closeOperation","deposit","getState__INTERNAL","isAtomDefault","isDone","isSelectorDefault","isValueCached","lookup","lookupSelectorSources","markAtomAsDefault","markAtomAsNotDefault","markDone","openOperation","readCachedValue","readonlySelectorFamily__INTERNAL","redoTransactionUpdate","redo__INTERNAL","registerSelector","selectorFamily__INTERNAL","selector__INTERNAL","setState__INTERNAL","subscribeToRootAtoms","target","timeline__INTERNAL","traceAllSelectorAtoms","traceSelectorAtoms","transaction__INTERNAL","undoTransactionUpdate","undo__INTERNAL","updateSelectorAtoms","withdraw","isString","Junction","data","config","a","b","_a","_b","externalStore","key","contentKey","content","aRelations","bRelations","rest","bPrev","aPrev","x","relations","k","input","setA","doNothing","become","nextVersionOfThing","originalThing","pass","params","fn","map","f","every","allTrue","ifNullish","alt","pipe","access","obj","recordToEntries","entriesToRecord","entries","mapObject","val","mob","isNonNullObject","isPlainObject","hasProperties","isValue","options","name","v","hasExactProperties","subscriber","value","state","__spreadValues","store","output","_c","_d","_e","atomUpdates","newValue","token","newAtom","setState","myTransaction","keys","newTransaction","getState","thrown","update","oldValue","core","type","errorId","atomToken","tl","atom","currentSelectorKey","currentSelectorTime","currentTransactionKey","currentTransactionTime","currentTransaction","unsubscribe","atomUpdate","atomOrFamilyKeys","timelineTransactionUpdate","__spreadProps","latestUpdate","timestamp","timelineData","tokenOrFamily","timelineKey","familyTimelineKey","_f","_g","_h","_i","_j","stateKey","familyKey","timeline","copiedAtom","selector","tx","_","source","emitUpdate","logger","evictDownStream","downstreamKeys","stowUpdate","setAtomState","next","setSelectorState","selectorKey","dependency","roots","sources","depth","r","root","alreadyRegistered","dependencyState","dependencyValue","stateToken","createReadWriteSelector","family","subject","get","set","getSelf","setSelf","mySelector","s","initialValue","createReadonlySelector","readonlySelector","existing","effect","idx","handle","subscribe","stringifyJson","json","subKey","fullKey","individualOptions","recallState","atomChange","capitalize","str","atomFamily","LOG_LEVELS","setLogLevel","preferredLevel","logger__INTERNAL","logLevel","useLogger","currentLogLevel","selectorFamily","Silo","fromStore","handler","handleUpdate","unsubFunction","dependencyUnsubFunctions","unsubFromDependency","subscribeToTransaction","subscribeToTimeline","redo","undo","transaction","runTransaction","parameters","isDefault"],"mappings":"6fAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,cAAAE,EAAA,UAAAC,EAAA,YAAAC,EAAA,uBAAAC,GAAA,qBAAAC,GAAA,sBAAAC,EAAA,qBAAAC,GAAA,yBAAAC,EAAA,mBAAAC,EAAA,qBAAAC,GAAA,eAAAC,EAAA,eAAAC,GAAA,mBAAAC,GAAA,YAAAC,EAAA,uBAAAC,EAAA,kBAAAC,EAAA,WAAAC,GAAA,sBAAAC,GAAA,kBAAAC,GAAA,WAAAC,GAAA,0BAAAC,EAAA,sBAAAC,GAAA,yBAAAC,GAAA,aAAAC,EAAA,kBAAAC,GAAA,oBAAAC,GAAA,qCAAAC,GAAA,0BAAAC,GAAA,mBAAAC,EAAA,qBAAAC,EAAA,6BAAAC,EAAA,uBAAAC,EAAA,uBAAAC,EAAA,yBAAAC,GAAA,WAAAC,EAAA,uBAAAC,EAAA,0BAAAC,EAAA,uBAAAC,EAAA,0BAAAC,EAAA,0BAAAC,GAAA,mBAAAC,EAAA,wBAAAC,GAAA,aAAAC,ICSA,OAAS,YAAAC,OAAgB,eC+BlB,IAAMC,EAAN,KAIL,CAsDM,YACNC,EACAC,EACC,CArDF,KAAgB,UAAY,IAAI,IAChC,KAAgB,SAAW,IAAI,IAG/B,KAAO,eAAiB,CAACC,EAAWC,IAAsB,GAAGD,CAAC,IAAIC,CAAC,GApDpE,IAAAC,EAAAC,EAgHE,GAVA,KAAK,EAAIL,EAAK,QAAQ,CAAC,EACvB,KAAK,EAAIA,EAAK,QAAQ,CAAC,EAEvB,KAAK,YAAcA,EAAK,YACxB,KAAK,UAAY,IAAI,KAAII,EAAAJ,EAAK,YAAL,YAAAI,EAAgB,IAAI,CAAC,CAACF,EAAGC,CAAC,I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S,EAAW,CACvBF,EACAV,EACAG,EAAenG,EAAS,QACd,CACV,GAAI,CACHwB,GAAckF,EAAOP,CAAK,CAC3B,OAASc,EAAQ,CAChB,GAAM,OAAOA,GAAW,SACvB,MAAMA,EAEP,MACD,CACA,IAAMhB,EAAQvD,EAASgE,EAAOP,CAAK,EACnC,GAAIF,IAAU,KACb,MAAM,IAAI,MACT,GAAGiG,GAAWxF,EAAM,IAAI,CAAC,KAAKA,EAAM,GAAG,yBACtCP,EAAM,OAAO,IACd,IACD,EAEDnE,EAAmBiE,EAAOD,EAAOG,CAAK,EACtCvF,GAAeuF,CAAK,CACrB,EAEawH,GAAY,CACxBjH,EACAP,EAAenG,EAAS,QAExB0G,EAAM,OAAS,OACZ3F,EAAc2F,EAAM,IAAKP,CAAK,EAC9BlF,GAAkByF,EAAM,IAAKP,CAAK","sourcesContent":["export * from \"./atom\"\nexport * from \"./caching\"\nexport * from \"./families\"\nexport * from \"./get-state-internal\"\nexport * from \"./operation\"\nexport * from \"./selector\"\nexport * from \"./set-state\"\nexport * from \"./store\"\nexport * from \"./subject\"\nexport * from \"./subscribe\"\nexport * from \"./timeline\"\nexport * from \"./transaction\"\n","import type {\n\tAtomToken,\n\tLogger,\n\tReadonlySelectorToken,\n\tSelectorToken,\n\tTimelineToken,\n\tTransactionToken,\n\tÆn,\n} from \"atom.io\"\nimport { isString } from \"fp-ts/string\"\nimport { Junction } from \"rel8/junction\"\n\nimport { doNothing } from \"~/packages/anvl/src/function\"\nimport { hasExactProperties } from \"~/packages/anvl/src/object\"\n\nimport type { Atom } from \"../atom\"\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 * from \"./deposit\"\nexport * from \"./lookup\"\nexport * from \"./withdraw\"\n\nexport type StoreCore = Pick<\n\tStore,\n\t| `atoms`\n\t| `atomsThatAreDefault`\n\t| `operation`\n\t| `readonlySelectors`\n\t| `selectorAtoms`\n\t| `selectorGraph`\n\t| `selectors`\n\t| `timelineAtoms`\n\t| `timelines`\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>>()\n\tpublic selectors = new Map<string, Selector<any>>()\n\tpublic readonlySelectors = new Map<string, ReadonlySelector<any>>()\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{\n\t\t\tbetween: [`upstreamSelectorKey`, `downstreamSelectorKey`],\n\t\t\tcardinality: `n:n`,\n\t\t},\n\t\t{\n\t\t\tisContent: hasExactProperties({ source: isString }),\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\tlogger: Logger | null\n\t\tlogger__INTERNAL: Logger\n\t} = {\n\t\tname: `DEFAULT`,\n\t\tlogger: { ...console, info: doNothing },\n\t\tlogger__INTERNAL: console,\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\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\tlogger__INTERNAL: console,\n\t\t\t\tlogger: {\n\t\t\t\t\t...console,\n\t\t\t\t\tinfo: doNothing,\n\t\t\t\t\t...store?.config?.logger,\n\t\t\t\t},\n\t\t\t\tname,\n\t\t\t}\n\t\t}\n\n\t\tstore?.atoms.forEach((atom) => {\n\t\t\tconst copiedAtom = { ...atom, subject: new Subject() } satisfies Atom<any>\n\t\t\tthis.atoms.set(atom.key, copiedAtom)\n\t\t})\n\t\tstore?.readonlySelectors.forEach((selector) => {\n\t\t\tselector.install(this)\n\t\t})\n\t\tstore?.selectors.forEach((selector) => {\n\t\t\tselector.install(this)\n\t\t})\n\t\tstore?.transactions.forEach((tx) => {\n\t\t\ttx.install(this)\n\t\t})\n\t\tstore?.timelines.forEach((timeline) => {\n\t\t\ttimeline.install(this)\n\t\t})\n\t}\n}\n\nexport const IMPLICIT = {\n\tSTORE_INTERNAL: undefined as Store | undefined,\n\tget STORE(): Store {\n\t\treturn this.STORE_INTERNAL ?? (this.STORE_INTERNAL = new Store(`DEFAULT`))\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: (g) => 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\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\tbRelations.forEach((a) => this.delete(a, b))\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\taRelations.forEach((b) => {\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`Multiple related keys were found for key \"${key}\": (${[...relations]\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\treturn [...relations][0]\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","import type { Refinement } from \"fp-ts/Refinement\"\nexport * from \"./curry\"\n\nexport type Æn = (...parameters: any[]) => any\n\nexport const doNothing = (): void => undefined\n\nexport const become =\n\t<T>(nextVersionOfThing: Modifier<T> | T) =>\n\t(originalThing: T | (() => 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\nexport type Applicator<X, Y> = (next: Modifier<X> | X) => Modifier<Y>\nexport type Modifier<T> = (thing: T) => T\n\nexport type OneOrMany<T> = T | T[]\n\nexport const isModifier =\n\t<T>(validate: Refinement<unknown, T>) =>\n\t(sample: T): Refinement<unknown, Modifier<T>> => {\n\t\tconst sampleIsValid = validate(sample)\n\t\tif (!sampleIsValid) {\n\t\t\tthrow new Error(`Invalid test case: JSON.stringify(${sample})`)\n\t\t}\n\t\treturn (input: unknown): input is Modifier<T> => {\n\t\t\tif (typeof input !== `function`) return false\n\t\t\tconst testResult = input(sample)\n\t\t\treturn validate(testResult)\n\t\t}\n\t}\n\nexport const pass =\n\t<Params extends ReadonlyArray<any>, Out>(...params: Params) =>\n\t(fn: (...params: Params) => Out): Out =>\n\t\tfn(...params)\n\nexport const typeOf =\n\t<T>(input: unknown) =>\n\t(isType: Refinement<unknown, T>): boolean =>\n\t\tisType(input)\n\nexport const raiseError = (message: string): never => {\n\tthrow new Error(message)\n}\n\nexport type Encapsulate<T extends (...args: any[]) => any> = (\n\t...args: Parameters<T>\n) => void\n\nexport const attempt = (fn: () => void): boolean => {\n\ttry {\n\t\tfn()\n\t\treturn true\n\t} catch (_) {\n\t\treturn false\n\t}\n}\n\nexport const fallback = <T>(fn: () => T, fallbackValue: T): T => {\n\ttry {\n\t\treturn fn()\n\t} catch (_) {\n\t\treturn fallbackValue\n\t}\n}\n","export * from \"./match\"\nexport * from \"./venn\"\n\nimport type { Refinement } from \"fp-ts/Refinement\"\n\nexport const each =\n\t<T>(isType: Refinement<unknown, T>) =>\n\t(input: unknown): T[] =>\n\t\tisType(input) ? [input] : Array.isArray(input) ? input.filter(isType) : []\n\nexport const lastOf = <T>(input: ReadonlyArray<T>): T | undefined =>\n\tinput[input.length - 1]\n\nexport const isArray =\n\t<T>(isType: Refinement<unknown, T>) =>\n\t(input: unknown): input is T[] =>\n\t\tArray.isArray(input) && input.every((item) => isType(item))\n\nexport const at =\n\t<T>(index: number) =>\n\t(input: T[]): T | undefined =>\n\t\tinput.at(index)\n\nexport const content =\n\t<T>(isType: Refinement<unknown, T>) =>\n\t(input: unknown): input is T | T[] =>\n\t\tisType(input) || isArray(isType)(input)\n\nexport const join = (separator?: string) => (a: string[]): string =>\n\ta.join(separator)\n\nexport const map =\n\t<I, O>(f: (value: I, index: number, array: I[]) => O) =>\n\t(a: I[]): O[] =>\n\t\ta.map(f)\n\nexport const reduce =\n\t<I, O>(f: (acc: O, value: I, index: number, array: I[]) => O, initial: O) =>\n\t(a: I[]): O =>\n\t\ta.reduce(f, initial)\n\nexport const slice = (start: number, end?: number) => <I>(a: I[]): I[] =>\n\ta.slice(start, end)\n\nexport const using =\n\t<I, O>(a: I[]) =>\n\t(f: (acc: O, value: I, index: number, array: I[]) => O) =>\n\t(initial: O): O =>\n\t\ta.reduce(f, initial)\n\nexport const reduceRight =\n\t<I, O>(f: (acc: O, value: I, index: number, array: I[]) => O, initial: O) =>\n\t(a: I[]): O =>\n\t\ta.reduceRight(f, initial)\n\nexport const reverse = <I>(a: I[]): I[] => a.reverse()\n\nexport const sort =\n\t<I>(a: I[]) =>\n\t(f?: (x: I, y: I) => number): I[] =>\n\t\tf ? a.sort(f) : a.sort()\n\nexport const sortBy =\n\t<I>(f: (value: I) => number) =>\n\t(a: I[]): I[] =>\n\t\ta.sort((x, y) => f(x) - f(y))\n\nexport const sortByDesc =\n\t<I>(f: (value: I) => number) =>\n\t(a: I[]): I[] =>\n\t\ta.sort((x, y) => f(y) - f(x))\n\nexport const every =\n\t<I>(f: (value: I, index: number, array: I[]) => boolean = Boolean) =>\n\t(a: I[]): boolean =>\n\t\ta.every(f)\n\nexport const allTrue = every((x: boolean) => x === true)\n\nexport const addTo =\n\t<I>(a: I[]) =>\n\t(x: I): I[] =>\n\t\ta.includes(x) ? a : [...a, x]\n\nexport const isEmptyArray = (input: unknown): input is [] =>\n\tArray.isArray(input) && input.length === 0\n\nexport const isOneOf =\n\t<T>(...args: ReadonlyArray<T>) =>\n\t(input: unknown): input is T =>\n\t\targs.includes(input as T)\n\nexport const filter =\n\t<I, O extends I>(f: (value: I, index: number, array: I[]) => value is O) =>\n\t(a: I[]): O[] =>\n\t\ta.filter(f)\n","import type { Refinement } from \"fp-ts/Refinement\"\n\nexport const isUndefined = (input: unknown): input is undefined =>\n\tinput === undefined\n\nexport const ifDefined = <T>(\n\tvalidate: Refinement<unknown, T>,\n): Refinement<unknown, T | undefined> =>\n\t((input) => isUndefined(input) || validate(input)) as Refinement<\n\t\tunknown,\n\t\tT | undefined\n\t>\n\nexport const isNull = (input: unknown): input is null => input === null\n\nexport const isNullish = (input: unknown): input is null | undefined =>\n\tisUndefined(input) || isNull(input)\n\nexport type NullSafeUnion<Base, Extension> = Extension extends null\n\t? Base\n\t: Base & Extension\n\nexport type NullSafeRest<MaybeArg, IfArg = MaybeArg> = MaybeArg extends null\n\t? [] | [undefined]\n\t: [IfArg]\n\nexport interface Discard {\n\treadonly _discard: unique symbol\n}\n\nexport const ifNullish =\n\t<X, Y>(alt: Y) =>\n\t(input: X): Exclude<X, null | undefined> | Y =>\n\t\t(input ?? alt) as Exclude<X, null | undefined> | Y\n","import type { Refinement } from \"fp-ts/Refinement\"\nimport { pipe } from \"fp-ts/function\"\n\nimport { allTrue, every } from \"../array\"\nimport { pass } from \"../function\"\nimport { ifNullish } from \"../nullish\"\nimport { access } from \"./access\"\nimport { recordToEntries } from \"./entries\"\nimport { mob } from \"./mapObject\"\n\nexport type PlainObject = Record<keyof any, unknown>\nexport type EmptyObject = Record<keyof any, never>\n\nexport const isNonNullObject = (input: unknown): input is object =>\n\ttypeof input === `object` && input !== null\n\nexport const isPlainObject = (input: unknown): input is PlainObject =>\n\tisNonNullObject(input) && Object.getPrototypeOf(input) === Object.prototype\n\nexport const isEmptyObject = (input: unknown): input is EmptyObject =>\n\tisPlainObject(input) && Object.keys(input).length === 0\n\n/* prettier-ignore */\nexport const isRecord =\n\t<KEY extends keyof any, VAL>(\n\t\tisKey: Refinement<keyof any, KEY>,\n\t\tisValue: Refinement<unknown, VAL>,\n\t) =>\n\t(input: unknown): input is Record<KEY, VAL> =>\n\t\tisPlainObject(input) &&\n\t\tObject.entries(input).every(([k, v]) => isKey(k) && isValue(v))\n/* prettier-ignore-end */\n\nexport type HasPropertiesOptions = {\n\treadonly allowExtraProperties?: boolean\n}\nexport const hasProperties = <OBJ extends object>(\n\tisValue: {\n\t\t[K in keyof OBJ]: Refinement<unknown, OBJ[K]>\n\t},\n\toptions: HasPropertiesOptions = { allowExtraProperties: false },\n): Refinement<unknown, OBJ> => {\n\tconst name = `{${recordToEntries(\n\t\tisValue as Record<keyof any, Refinement<any, any>>,\n\t)\n\t\t.map(([k, v]) => String(k) + `:` + v.name)\n\t\t.join(`,`)}}`\n\n\tconst _ = {\n\t\t[name]: (input: unknown): input is OBJ =>\n\t\t\tisPlainObject(input) &&\n\t\t\tpipe(\n\t\t\t\tisValue,\n\t\t\t\tObject.entries,\n\t\t\t\tevery(([key, val]) => key in input || val(undefined)),\n\t\t\t) &&\n\t\t\tpipe(\n\t\t\t\tinput,\n\t\t\t\tmob((val, key) =>\n\t\t\t\t\tpipe(\n\t\t\t\t\t\tisValue,\n\t\t\t\t\t\taccess(key),\n\t\t\t\t\t\tifNullish(() => options.allowExtraProperties),\n\t\t\t\t\t\tpass(val),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tObject.values,\n\t\t\t\tallTrue,\n\t\t\t),\n\t}\n\treturn _[name]\n}\n\nexport const doesExtend =\n\t/* alias for hasExactProperties with allowExtraProperties */\n\t<OBJ extends object>(\n\t\tisValue: {\n\t\t\t[K in keyof OBJ]: Refinement<unknown, OBJ[K]>\n\t\t},\n\t): Refinement<unknown, OBJ> =>\n\t\thasProperties(isValue, { allowExtraProperties: true })\n\nexport const hasExactProperties =\n\t/* alias for hasProperties without allowExtraProperties */\n\t<OBJ extends object>(\n\t\tisValue: {\n\t\t\t[K in keyof OBJ]: Refinement<unknown, OBJ[K]>\n\t\t},\n\t): Refinement<unknown, OBJ> =>\n\t\thasProperties(isValue, { allowExtraProperties: false })\n","export const key =\n\t<T extends object>(k: keyof T) =>\n\t(obj: Exclude<object, null>): unknown =>\n\t\t(obj as Record<keyof any, any>)[k]\n\nexport const access = <V, T extends Record<keyof any, V>>(\n\tk: keyof any,\n): {\n\t(obj: T): T[keyof T] | undefined\n\tin: (obj: T) => T[keyof T] | undefined\n} =>\n\tObject.assign((obj: T) => obj[k as keyof T], {\n\t\tin: (obj: T) => obj[k as keyof T],\n\t})\n","export type Entries<K extends keyof any, V> = [key: K, value: V][]\n\nexport const recordToEntries = <K extends keyof any, V>(\n\tobj: Record<K, V>,\n): Entries<K, V> => Object.entries(obj) as Entries<K, V>\n\nexport const entriesToRecord = <K extends keyof any, V>(\n\tentries: Entries<K, V>,\n): Record<K, V> => Object.fromEntries(entries) as Record<K, V>\n","import { pipe } from \"fp-ts/function\"\n\nimport { map } from \"../array\"\nimport { entriesToRecord, recordToEntries } from \"./entries\"\n\nexport const mapObject = <K extends keyof any, I, O>(\n\tobj: Record<K, I>,\n\tfn: (val: I, key: K) => O,\n): Record<K, O> =>\n\tpipe(\n\t\tobj,\n\t\trecordToEntries,\n\t\tmap(([key, val]) => [key, fn(val, key)] as const),\n\t\tentriesToRecord,\n\t)\n\nexport const mob =\n\t<K extends keyof any, I, O>(fn: (val: I, key: K) => O) =>\n\t(obj: Record<K, I>): Record<K, O> =>\n\t\tmapObject(obj, fn)\n","type Subscriber<T> = (value: T) => void\n\nexport class Subject<T> {\n\tpublic subscribers: Map<string, Subscriber<T>> = new Map()\n\n\tpublic subscribe(key: string, subscriber: Subscriber<T>): () => 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\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\treturn {\n\t\tkey: state.key,\n\t\ttype: state.type,\n\t\t...(`family` in state && { family: state.family }),\n\t} as any\n}\n","import type { Store } from \"../store\"\n\nexport const abortTransaction = (store: Store): void => {\n\tif (store.transactionStatus.phase === `idle`) {\n\t\tstore.config.logger?.warn(\n\t\t\t`abortTransaction called outside of a transaction. This is probably a bug.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.transactionStatus = { phase: `idle` }\n\tstore.config.logger?.info(`ðª`, `transaction fail`)\n}\n","import type { AtomToken, Æn } from \"atom.io\"\nimport { setState } 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.config.logger?.warn(\n\t\t\t`abortTransaction called outside of a transaction. This is probably a bug.`,\n\t\t)\n\t\treturn\n\t}\n\n\tstore.transactionStatus.phase = `applying`\n\tstore.transactionStatus.output = output\n\tconst { atomUpdates } = store.transactionStatus\n\tstore.config.logger?.info(\n\t\t`ð applying transaction \"${store.transactionStatus.key}\" with ${atomUpdates.length} updates.`,\n\t)\n\tstore.config.logger?.info(`ð the updates are:`, atomUpdates)\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\tconst newAtom = store.transactionStatus.core.atoms.get(token.key)\n\t\t\tif (!newAtom) {\n\t\t\t\tthrow new Error(\n\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)\n\t\t\t}\n\t\t\tstore.atoms.set(newAtom.key, newAtom)\n\t\t\tstore.valueMap.set(newAtom.key, newAtom.default)\n\t\t\tstore.config.logger?.info(`ð§`, `add atom \"${newAtom.key}\"`)\n\t\t}\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 === null) {\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.transactionStatus = { phase: `idle` }\n\tstore.config.logger?.info(`ð¬`, `transaction done`)\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\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\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.config.logger?.info(\n\t\t`ð«`,\n\t\t`transaction \"${key}\" started in store \"${store.config.name}\"`,\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.config.logger?.error(`Transaction ${options.key} failed`, 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 { 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.config.logger?.info(` â redo 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 === null) {\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.config.logger?.info(` â® undo transaction \"${update.key}\" (undo)`)\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 === null) {\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, ReadonlySelectorToken, SelectorToken } from \"atom.io\"\n\nimport { target } from \"../transaction\"\nimport type { Store } from \"./store\"\n\nexport function lookup(\n\tkey: string,\n\tstore: Store,\n): AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown> {\n\tconst core = target(store)\n\tlet type: string = core.atoms.has(key)\n\t\t? `atom`\n\t\t: core.selectors.has(key)\n\t\t? `selector`\n\t\t: core.readonlySelectors.has(key)\n\t\t? `readonly_selector`\n\t\t: ``\n\tif (!type) {\n\t\tconst errorId = Math.random().toString(36)\n\t\ttype = `ðš This state could not be found by lookup! Check the console for \"${errorId}\"`\n\t\tstore.config.logger?.error(\n\t\t\t`${errorId}: Key \"${key}\" does not exist in the store.`,\n\t\t)\n\t}\n\treturn { key, type } as any\n}\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 === null) {\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.config.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\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 === null) {\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.config.logger?.error(\n\t\t\t\t\t\t\t`Timeline \"${tl.key}\" was unable to resolve transaction \"${tl.transactionKey}. This is probably a bug.`,\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\ttl.history.push(timelineTransactionUpdate)\n\t\t\t\t\t\t\t\ttl.at = tl.history.length\n\t\t\t\t\t\t\t\ttl.subject.next(timelineTransactionUpdate)\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.config.logger?.info(\n\t\t\t\t\t\t\t\t`â timeline \"${tl.key}\" 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\t\t\t\t\ttl.history.push(latestUpdate)\n\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`â timeline \"${tl.key}\" 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.config.logger?.info(\n\t\t\t\t\t\t\t` â timeline \"${tl.key}\" 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) tl.subject.next(latestUpdate)\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\ttl.history.push(atomUpdate)\n\t\t\t\ttl.subject.next(atomUpdate)\n\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t`â timeline \"${tl.key}\" got an atom_update to \"${atom.key}\"`,\n\t\t\t\t)\n\t\t\t\ttl.at = tl.history.length\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.config.logger?.info(`â© redo \"${token.key}\"`)\n\tconst timelineData = store.timelines.get(token.key)\n\tif (!timelineData) {\n\t\tstore.config.logger?.error(\n\t\t\t`Failed to redo on timeline \"${token.key}\". This timeline has not been initialized.`,\n\t\t)\n\t\treturn\n\t}\n\tif (timelineData.at === timelineData.history.length) {\n\t\tstore.config.logger?.warn(\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.config.logger?.info(\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.config.logger?.info(`⪠undo \"${token.key}\"`)\n\tconst timelineData = store.timelines.get(token.key)\n\tif (!timelineData) {\n\t\tstore.config.logger?.error(\n\t\t\t`Failed to undo on timeline \"${token.key}\". This timeline has not been initialized.`,\n\t\t)\n\t\treturn\n\t}\n\tif (timelineData.at === 0) {\n\t\tstore.config.logger?.warn(\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.config.logger?.info(\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\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\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.config.logger?.error(\n\t\t\t\t`â Failed to add atom \"${tokenOrFamily.key}\" to timeline \"${options.key}\" because it 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\tif (!core.atoms.has(token.key)) {\n\t\t\t\t\taddAtomToTimeline(token, 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.config.logger?.error(\n\t\t\t\t\t\t`â Failed to add atom \"${token.key}\" to timeline \"${options.key}\" because its family \"${token.family.key}\" 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 { type Timeline, addAtomToTimeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport { target } from \"../transaction\"\nimport type { Store } from \"./store\"\n\nexport function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | null\nexport function withdraw<T>(\n\ttoken: SelectorToken<T>,\n\tstore: Store,\n): Selector<T> | null\nexport function withdraw<T>(\n\ttoken: StateToken<T>,\n\tstore: Store,\n): Atom<T> | Selector<T> | null\nexport function withdraw<T>(\n\ttoken: ReadonlySelectorToken<T>,\n\tstore: Store,\n): ReadonlySelector<T> | null\nexport function withdraw<T>(\n\ttoken: TransactionToken<T>,\n\tstore: Store,\n): Transaction<T extends Æn ? T : never> | null\nexport function withdraw<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Store,\n): Atom<T> | ReadonlySelector<T> | Selector<T> | null\nexport function withdraw<T>(token: TimelineToken, store: Store): Timeline | null\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| null {\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.config.logger?.info(`ð ïž add ${token.type} \"${token.key}\"`)\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 null\n}\n","import type { Store } from \"./store\"\nimport { IMPLICIT } from \"./store\"\nimport { target } from \"./transaction\"\n\nexport const cacheValue = (\n\tkey: string,\n\tvalue: unknown,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\ttarget(store).valueMap.set(key, value)\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","import type {\n\tAtomToken,\n\tReadonlySelectorToken,\n\tSelectorToken,\n\tStore,\n} from \"atom.io\"\n\nimport { lookup } from \"../store\"\nimport { target } from \"../transaction\"\n\nexport const lookupSelectorSources = (\n\tkey: string,\n\tstore: Store,\n): (\n\t| AtomToken<unknown>\n\t| ReadonlySelectorToken<unknown>\n\t| SelectorToken<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 }]) => lookup(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.config.logger?.info(`>> read \"${state.key}\"`)\n\t\treturn readCachedValue(state.key, store)\n\t}\n\tif (state.type !== `atom`) {\n\t\tstore.config.logger?.info(`-> calc \"${state.key}\"`)\n\t\treturn state.get()\n\t}\n\tstore.config.logger?.error(\n\t\t`Attempted to get atom \"${state.key}\", which was never initialized in store \"${store.config.name}\".`,\n\t)\n\treturn state.default\n}\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 = (token: StateToken<any>, store: Store): void => {\n\tconst core = target(store)\n\tif (core.operation.open) {\n\t\tstore.config.logger?.error(\n\t\t\t`â failed to setState to \"${token.key}\" during a setState for \"${core.operation.token.key}\"`,\n\t\t)\n\t\tthrow Symbol(`violation`)\n\t}\n\tcore.operation = {\n\t\topen: true,\n\t\tdone: new Set(),\n\t\tprev: new Map(store.valueMap),\n\t\ttime: Date.now(),\n\t\ttoken,\n\t}\n\tstore.config.logger?.info(\n\t\t`â operation start from \"${token.key}\" 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\tcore.operation = { open: false }\n\tstore.config.logger?.info(`ðŽ operation done`)\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.config.logger?.warn(\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.config.logger?.warn(\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 { StateUpdate, Store } from \"atom.io\"\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.config\n\tlogger?.info(\n\t\t`ð¢ ${state.type} \"${key}\" went (`,\n\t\tupdate.oldValue,\n\t\t`->`,\n\t\tupdate.newValue,\n\t\t`)`,\n\t)\n\tstate.subject.next(update)\n}\n","import type { Atom } from \"../atom\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport { target } from \"../transaction\"\n\nexport const evictDownStream = <T>(\n\tstate: Atom<T>,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst core = target(store)\n\tconst downstreamKeys = core.selectorAtoms.getRelatedKeys(state.key)\n\tstore.config.logger?.info(\n\t\t` || ${downstreamKeys?.size ?? `none`} downstream:`,\n\t\tdownstreamKeys,\n\t)\n\tif (core.operation.open) {\n\t\tstore.config.logger?.info(` ||`, [...core.operation.done], `already done`)\n\t}\n\tif (downstreamKeys) {\n\t\tfor (const key of downstreamKeys) {\n\t\t\tif (isDone(key, store)) {\n\t\t\t\tstore.config.logger?.info(` || ${key} already done`)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst state = core.selectors.get(key) ?? core.readonlySelectors.get(key)\n\t\t\tif (!state) {\n\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t` || ${key} was not found in selectors or readonlySelectors`,\n\t\t\t\t)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcore.valueMap.delete(key)\n\t\t\tstore.config.logger?.info(` xx evicted \"${key}\"`)\n\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 type { Store } from \"../store\"\n\nexport const stowUpdate = <T>(\n\tstate: Atom<T>,\n\tupdate: StateUpdate<T>,\n\tstore: Store,\n): void => {\n\tconst { key } = state\n\tconst { logger } = store.config\n\tif (store.transactionStatus.phase !== `building`) {\n\t\tstore.config.logger?.warn(\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 atomUpdate: KeyedStateUpdate<T> = { key, ...update }\n\tif (state.family) {\n\t\tatomUpdate.family = state.family\n\t}\n\tstore.transactionStatus.atomUpdates.push(atomUpdate)\n\tlogger?.info(`ð ${key} stowed (`, update.oldValue, `->`, update.newValue, `)`)\n}\n","import { become } from \"~/packages/anvl/src/function\"\n\nimport 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 { IMPLICIT } from \"../store\"\nimport type { Store } from \"../store\"\nimport { emitUpdate } from \"./emit-update\"\nimport { evictDownStream } from \"./evict-downstream\"\nimport { stowUpdate } from \"./stow-update\"\n\nexport const setAtomState = <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\tconst newValue = become(next)(oldValue)\n\tstore.config.logger?.info(`<< setting atom \"${atom.key}\" to`, newValue)\n\tcacheValue(atom.key, newValue, store)\n\tif (isAtomDefault(atom.key, store)) {\n\t\tmarkAtomAsNotDefault(atom.key, store)\n\t}\n\tmarkDone(atom.key, store)\n\tstore.config.logger?.info(\n\t\t` || evicting caches downstream from \"${atom.key}\"`,\n\t)\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 { become } from \"~/packages/anvl/src/function\"\n\nimport { getState__INTERNAL } from \"../get-state-internal\"\nimport type { Selector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\n\nexport const setSelectorState = <T>(\n\tselector: Selector<T>,\n\tnext: T | ((oldValue: T) => T),\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst oldValue = getState__INTERNAL(selector, store)\n\tconst newValue = become(next)(oldValue)\n\n\tstore.config.logger?.info(`<< setting selector \"${selector.key}\" to`, newValue)\n\tstore.config.logger?.info(` || propagating change made to \"${selector.key}\"`)\n\n\tselector.set(newValue)\n}\n","import type { Atom } from \"../atom\"\nimport type { Selector } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT } from \"../store\"\nimport { setAtomState } from \"./set-atom-state\"\nimport { setSelectorState } from \"./set-selector-state\"\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 (`set` in state) {\n\t\tsetSelectorState(state, value, store)\n\t} else {\n\t\tsetAtomState(state, value, store)\n\t}\n}\n","import type {\n\tAtomToken,\n\tReadonlySelectorToken,\n\tStateToken,\n\tStore,\n} from \"atom.io\"\n\nimport { lookupSelectorSources } from \"./lookup-selector-sources\"\n\nexport const traceSelectorAtoms = (\n\tselectorKey: string,\n\tdependency: ReadonlySelectorToken<unknown> | StateToken<unknown>,\n\tstore: Store,\n): AtomToken<unknown>[] => {\n\tconst roots: AtomToken<unknown>[] = []\n\n\tconst sources = lookupSelectorSources(dependency.key, store)\n\tlet depth = 0\n\twhile (sources.length > 0) {\n\t\t// biome-ignore lint/style/noNonNullAssertion: just checked length ^^^\n\t\tconst source = sources.shift()!\n\t\t++depth\n\t\tif (depth > 999) {\n\t\t\tthrow new Error(\n\t\t\t\t`Maximum selector dependency depth exceeded in selector \"${selectorKey}\".`,\n\t\t\t)\n\t\t}\n\n\t\tif (source.type !== `atom`) {\n\t\t\tsources.push(...lookupSelectorSources(source.key, store))\n\t\t} else {\n\t\t\troots.push(source)\n\t\t}\n\t}\n\n\treturn roots\n}\n\nexport const traceAllSelectorAtoms = (\n\tselectorKey: string,\n\tstore: Store,\n): AtomToken<unknown>[] => {\n\tconst sources = lookupSelectorSources(selectorKey, store)\n\treturn sources.flatMap((source) =>\n\t\tsource.type === `atom`\n\t\t\t? source\n\t\t\t: traceSelectorAtoms(selectorKey, source, 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.config.logger?.info(\n\t\t\t` || adding root for \"${selectorKey}\": ${dependency.key}`,\n\t\t)\n\t\treturn\n\t}\n\tconst roots = traceSelectorAtoms(selectorKey, dependency, store)\n\tstore.config.logger?.info(\n\t\t` || adding roots for \"${selectorKey}\":`,\n\t\troots.map((r) => r.key),\n\t)\n\tfor (const root of roots) {\n\t\tcore.selectorAtoms = core.selectorAtoms.set({\n\t\t\tselectorKey,\n\t\t\tatomKey: root.key,\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 === null) {\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\tif (alreadyRegistered) {\n\t\t\tstore.config.logger?.info(\n\t\t\t\t` || ${selectorKey} <- ${dependency.key} =`,\n\t\t\t\tdependencyValue,\n\t\t\t)\n\t\t} else {\n\t\t\tstore.config.logger?.info(\n\t\t\t\t`ð registerSelector \"${selectorKey}\" <- ( \"${dependency.key}\" =`,\n\t\t\t\tdependencyValue,\n\t\t\t\t`)`,\n\t\t\t)\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 === null) {\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 {\n\tFamilyMetadata,\n\tSelectorOptions,\n\tSelectorToken,\n\tStore,\n} from \"atom.io\"\n\nimport { become } from \"~/packages/anvl/src/function\"\n\nimport { cacheValue } from \"../caching\"\nimport { markDone } from \"../operation\"\nimport type { StoreCore } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { registerSelector } from \"./register-selector\"\nimport { type Selector, selector__INTERNAL } from \"./selector-internal\"\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, store)\n\t\treturn value\n\t}\n\n\tconst setSelf = (next: T | ((oldValue: T) => T)): void => {\n\t\tconst oldValue = getSelf()\n\t\tstore.config.logger?.info(\n\t\t\t` <- \"${options.key}\" went (`,\n\t\t\toldValue,\n\t\t\t`->`,\n\t\t\tnext,\n\t\t\t`)`,\n\t\t)\n\t\tconst newValue = become(next)(oldValue)\n\t\tcacheValue(options.key, newValue, 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) => selector__INTERNAL(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.config.logger?.info(` âš \"${options.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 { registerSelector } from \"./register-selector\"\nimport type { ReadonlySelector } from \"./selector-internal\"\nimport { selector__INTERNAL } from \"./selector-internal\"\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, 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) => selector__INTERNAL(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.config.logger?.info(` âš \"${options.key}\" =`, initialValue)\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 { IMPLICIT, 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 selector__INTERNAL<T>(\n\toptions: SelectorOptions<T>,\n\tfamily?: FamilyMetadata,\n\tstore?: Store,\n): SelectorToken<T>\nexport function selector__INTERNAL<T>(\n\toptions: ReadonlySelectorOptions<T>,\n\tfamily?: FamilyMetadata,\n\tstore?: Store,\n): ReadonlySelectorToken<T>\nexport function selector__INTERNAL<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\n\tif (core.selectors.has(options.key)) {\n\t\tstore.config.logger?.error(\n\t\t\t`Key \"${options.key}\" already exists in the store.`,\n\t\t)\n\t}\n\n\tif (!(`set` in options)) {\n\t\treturn createReadonlySelector(options, family, store, core)\n\t}\n\treturn createReadWriteSelector(options, family, store, core)\n}\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 roots = traceAllSelectorAtoms(key, store)\n\treturn roots.every((root) => isAtomDefault(root.key, store))\n}\n","import type {\n\tAtomOptions,\n\tAtomToken,\n\tFamilyMetadata,\n\tUpdateHandler,\n} from \"atom.io\"\nimport { setState, subscribe } from \"atom.io\"\n\nimport { cacheValue } from \"../caching\"\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\tsubject: Subject<{ newValue: T; oldValue: T }>\n\tdefault: T\n}\n\nexport function atom__INTERNAL<T>(\n\toptions: AtomOptions<T>,\n\tfamily?: FamilyMetadata,\n\tstore: Store = IMPLICIT.STORE,\n): AtomToken<T> {\n\tconst core = target(store)\n\tconst existing = core.atoms.get(options.key)\n\tif (existing) {\n\t\tstore.config.logger?.info?.(\n\t\t\t`Key \"${options.key}\" already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing)\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom = {\n\t\t...options,\n\t\tsubject,\n\t\ttype: `atom`,\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, store)\n\tconst token = deposit(newAtom)\n\toptions.effects?.forEach((effect, idx) =>\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, `effects[${idx}]`, store),\n\t\t}),\n\t)\n\tstore.subject.atomCreation.next(token)\n\treturn token as AtomToken<T>\n}\n","export * from \"./json-interface\"\nimport type * as Json from \"./json\"\nexport { Json }\n\nexport const parseJson = <S extends Stringified<Json.Serializable>>(\n\tstr: S | string,\n): S extends Stringified<infer J> ? J : Json.Serializable => JSON.parse(str)\n\nexport type Stringified<J extends Json.Serializable> = string & { __json: J }\n\nexport const stringifyJson = <J extends Json.Serializable>(\n\tjson: J,\n): Stringified<J> => JSON.stringify(json) as Stringified<J>\n\nexport type Empty = Record<string, never>\n\nexport const JSON_TYPE_NAMES = [\n\t`array`,\n\t`boolean`,\n\t`null`,\n\t`number`,\n\t`object`,\n\t`string`,\n] as const\n\nexport type JsonTypeName = typeof JSON_TYPE_NAMES[number]\n\nexport interface JsonTypes extends Record<JsonTypeName, Json.Serializable> {\n\tarray: Json.Array\n\tboolean: boolean\n\tnull: null\n\tnumber: number\n\tobject: Json.Object\n\tstring: string\n}\n\nexport const JSON_DEFAULTS: JsonTypes = {\n\tarray: [],\n\tboolean: false,\n\tnull: null,\n\tnumber: 0,\n\tobject: {},\n\tstring: ``,\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 { atom__INTERNAL } from \"../atom\"\nimport { IMPLICIT, type Store, deposit, withdraw } from \"../store\"\nimport { Subject } from \"../subject\"\n\nexport function atomFamily__INTERNAL<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\treturn 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\ttoken = atom__INTERNAL<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}\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 { selector__INTERNAL } from \"../selector\"\nimport { type Store, deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\n\nexport function readonlySelectorFamily__INTERNAL<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 selector__INTERNAL<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 {\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 { selector__INTERNAL } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { IMPLICIT, deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { target } from \"../transaction\"\nimport { readonlySelectorFamily__INTERNAL } from \"./readonly-selector-family-internal\"\n\nexport function selectorFamily__INTERNAL<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n\tstore?: Store,\n): SelectorFamily<T, K>\nexport function selectorFamily__INTERNAL<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n\tstore?: Store,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily__INTERNAL<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 readonlySelectorFamily__INTERNAL(options, store)\n\t}\n\tconst core = target(store)\n\tconst subject = new Subject<SelectorToken<T>>()\n\n\treturn 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 = selector__INTERNAL<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}\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.config.logger?.warn(\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 { withdraw } 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((atomToken) => {\n\t\t\t\t\tconst atom = withdraw(atomToken, store)\n\t\t\t\t\tif (atom === null) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Atom \"${atomToken.key}\", 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.config.logger?.info(\n\t\t\t\t\t\t\t\t`ð¢ selector \"${state.key}\" saw root \"${atomToken.key}\" go (`,\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\t`)`,\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\tconst newValue = getState__INTERNAL(state, store)\n\t\t\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t\t\t` <- \"${state.key}\" 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\t`)`,\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","export const capitalize = (str: string): string =>\n\tstr[0].toUpperCase() + str.slice(1)\n","import type { Subject } from \"atom.io/internal\"\nimport { atomFamily__INTERNAL, atom__INTERNAL } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { AtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n\tmutable?: boolean\n}\n\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T> {\n\treturn atom__INTERNAL<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K> {\n\treturn atomFamily__INTERNAL<T, K>(options)\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nimport { doNothing } from \"~/packages/anvl/src/function\"\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tLOG_LEVELS.forEach((logLevel) => {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = doNothing\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== doNothing,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { selectorFamily__INTERNAL, selector__INTERNAL } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn selector__INTERNAL(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn selectorFamily__INTERNAL(options)\n}\n","import {\n\tStore,\n\tatomFamily__INTERNAL,\n\tatom__INTERNAL,\n\tredo__INTERNAL,\n\tselectorFamily__INTERNAL,\n\tselector__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst store = new Store(name, fromStore)\n\t\tthis.store = store\n\t\tthis.atom = (options) => atom__INTERNAL(options, undefined, store)\n\t\tthis.atomFamily = (options) => atomFamily__INTERNAL(options, store)\n\t\tthis.selector = (options) =>\n\t\t\tselector__INTERNAL(options, undefined, store) as any\n\t\tthis.selectorFamily = (options) =>\n\t\t\tselectorFamily__INTERNAL(options, store) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, store)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, store)\n\t\tthis.getState = (token) => getState(token, store)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, store)\n\t\t;(this.subscribe = (token, handler, key) =>\n\t\t\tsubscribe(token, handler, key, store)),\n\t\t\t(this.undo = (token) => undo__INTERNAL(token, store))\n\t\tthis.redo = (token) => redo__INTERNAL(token, store)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tÆn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport const subscribe = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): (() => void) => {\n\tconst state = withdraw<T>(token, store)\n\tif (state === null) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`ð subscribe to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`ð unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`ð unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<Æ extends Æn> = (\n\tdata: TransactionUpdate<Æ>,\n) => void\n\nexport const subscribeToTransaction = <Æ extends Æn>(\n\ttoken: TransactionToken<Æ>,\n\thandleUpdate: TransactionUpdateHandler<Æ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === null) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`ð subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`ð unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === null) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`ð subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`ð unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport {\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal/\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, Æn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<Æ extends Æn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<Æ>\n\toutput: ReturnType<Æ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<Æ extends Æn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<Æ>\n) => ReturnType<Æ>\n\nexport type Write<Æ extends Æn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<Æ>\n) => ReturnType<Æ>\n\nexport type TransactionOptions<Æ extends Æn> = {\n\tkey: string\n\tdo: Write<Æ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer Æ> ? Æ : never\n\nexport function transaction<Æ extends Æn>(\n\toptions: TransactionOptions<Æ>,\n): TransactionToken<Æ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<Æ extends Æn>(token: TransactionToken<Æ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<Æ>): ReturnType<Æ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n","import {\n\tIMPLICIT,\n\tcloseOperation,\n\tgetState__INTERNAL,\n\tisAtomDefault,\n\tisSelectorDefault,\n\topenOperation,\n\tsetState__INTERNAL,\n\twithdraw,\n} from \"atom.io/internal\"\nimport * as __INTERNAL__ from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nimport type { Æn } from \"~/packages/anvl/src/function\"\nimport { capitalize } from \"~/packages/anvl/src/string/capitalize\"\n\nexport { Æn }\n\nexport * from \"./atom\"\nexport * from \"./logger\"\nexport * from \"./selector\"\nexport * from \"./silo\"\nexport * from \"./subscribe\"\nexport * from \"./timeline\"\nexport * from \"./transaction\"\nexport { __INTERNAL__ }\nexport type { Store } from \"atom.io/internal\"\nexport type { Json } from \"atom.io/json\"\n\nexport type AtomToken<_> = {\n\tkey: string\n\ttype: `atom`\n\tfamily?: FamilyMetadata\n\t__brand?: _\n}\nexport type SelectorToken<_> = {\n\tkey: string\n\ttype: `selector`\n\tfamily?: FamilyMetadata\n\t__brand?: _\n}\nexport type StateToken<T> = AtomToken<T> | SelectorToken<T>\n\nexport type ReadonlySelectorToken<_> = {\n\tkey: string\n\ttype: `readonly_selector`\n\tfamily?: FamilyMetadata\n\t__brand?: _\n}\n\nexport type FamilyMetadata = {\n\tkey: string\n\tsubKey: string\n}\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Store = IMPLICIT.STORE,\n): T => {\n\tconst state = withdraw<T>(token, store)\n\tif (state === null) {\n\t\tthrow new Error(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n\treturn getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\ttry {\n\t\topenOperation(token, store)\n\t} catch (thrown) {\n\t\tif (!(typeof thrown === `symbol`)) {\n\t\t\tthrow thrown\n\t\t}\n\t\treturn\n\t}\n\tconst state = withdraw(token, store)\n\tif (state === null) {\n\t\tthrow new Error(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n\tsetState__INTERNAL(state, value, store)\n\tcloseOperation(store)\n}\n\nexport const isDefault = (\n\ttoken: ReadonlySelectorToken<unknown> | StateToken<unknown>,\n\tstore: Store = IMPLICIT.STORE,\n): boolean =>\n\ttoken.type === `atom`\n\t\t? isAtomDefault(token.key, store)\n\t\t: isSelectorDefault(token.key, store)\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/atom.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","IMPLICIT","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL","withdraw"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,YAAY,QAAQ;;;ACCpB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,OAAO;AAAA,EACjC;AACA,SAAO,WAAc,OAAO;AAC7B;AA+CO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,OAAO;AAAA,EACvC;AACA,SAAO,iBAAuB,OAAO;AACtC;;;ACjGA,SAAS,gBAAgB;AAGlB,IAAM,QAAQ,MAAY;AAG1B,IAAM,aAA0C;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AACD;AAEO,IAAM,cAAc,CAC1B,gBACA,QAAe,SAAS,UACd;AACV,QAAM,EAAE,iBAAiB,IAAI,MAAM;AACnC,MAAI,mBAAmB,MAAM;AAC5B,UAAM,OAAO,SAAS;AAAA,EACvB,OAAO;AACN,UAAM,OAAO,SAAS,mBAAK;AAC3B,eAAW,QAAQ,CAAC,aAAa;AAChC,UAAI,WAAW,QAAQ,QAAQ,IAAI,WAAW,QAAQ,cAAc,GAAG;AAEtE,cAA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AAAA,EACD;AACA,QAAM,SACL,KAAG,YAAS,OAAO,KAAK,MAAxB,YAAgC,2BAAwB,OAAO,KAAK;AACrE,MAAI,UAAU,MAAM;AACnB,UAAM,IAAI;AAAA,MACT,GAAG,WAAW,MAAM,IAAI,CAAC,KAAK,MAAM,GAAG,yBACtC,MAAM,OAAO,IACd;AAAA,IACD;AAAA,EACD;AACA,EAAG,sBAAmB,OAAO,OAAO,KAAK;AACzC,EAAG,kBAAe,KAAK;AACxB;AAEO,IAAM,YAAY,CACxB,OACA,QAAkB,YAAS,UAE3B,MAAM,SAAS,SACT,iBAAc,MAAM,KAAK,KAAK,IAC9B,qBAAkB,MAAM,KAAK,KAAK","sourcesContent":["import * as IO from \"atom.io/internal\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport * from \"./atom\"\nexport * from \"./logger\"\nexport * from \"./selector\"\nexport * from \"./silo\"\nexport {\n\tsubscribe,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n\tKeyedStateUpdate,\n\tStateUpdate,\n\tUpdateHandler,\n} from \"./subscribe\"\nexport * from \"./timeline\"\nexport * from \"./transaction\"\n\nexport type Æn = (...parameters: any[]) => any\n\nexport type AtomToken<_> = {\n\tkey: string\n\ttype: `atom`\n\tfamily?: FamilyMetadata\n\t__brand?: _\n}\nexport interface MutableAtomToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n> extends AtomToken<T> {\n\t__asJSON?: J\n\t__update?: T extends Transceiver<infer Update> ? Update : never\n}\nexport type SelectorToken<_> = {\n\tkey: string\n\ttype: `selector`\n\tfamily?: FamilyMetadata\n\t__brand?: _\n}\nexport type StateToken<T> = AtomToken<T> | SelectorToken<T>\n\nexport type ReadonlySelectorToken<_> = {\n\tkey: string\n\ttype: `readonly_selector`\n\tfamily?: FamilyMetadata\n\t__brand?: _\n}\n\nexport type FamilyMetadata = {\n\tkey: string\n\tsubKey: string\n}\n\nexport const capitalize = (str: string): string =>\n\tstr[0].toUpperCase() + str.slice(1)\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Store = IO.IMPLICIT.STORE,\n): T => {\n\tconst state =\n\t\tIO.withdraw(token, store) ?? IO.withdrawNewFamilyMember(token, store)\n\tif (state === null) {\n\t\tthrow new Error(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n\treturn IO.getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Store = IO.IMPLICIT.STORE,\n): void => {\n\ttry {\n\t\tIO.openOperation(token, store)\n\t} catch (thrown) {\n\t\tif (!(typeof thrown === `symbol`)) {\n\t\t\tthrow thrown\n\t\t}\n\t\treturn\n\t}\n\tconst state =\n\t\tIO.withdraw(token, store) ?? IO.withdrawNewFamilyMember(token, store)\n\tif (state === null) {\n\t\tthrow new Error(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n\tIO.setState__INTERNAL(state, value, store)\n\tIO.closeOperation(store)\n}\n\nexport const isDefault = (\n\ttoken: ReadonlySelectorToken<unknown> | StateToken<unknown>,\n\tstore: Store = IO.IMPLICIT.STORE,\n): boolean =>\n\ttoken.type === `atom`\n\t\t? IO.isAtomDefault(token.key, store)\n\t\t: IO.isSelectorDefault(token.key, store)\n","import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options)\n\t}\n\treturn createAtom<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tLOG_LEVELS.forEach((logLevel) => {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tÆn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === null) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`ð adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`ð unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`ð unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<Æ extends Æn> = (\n\tdata: TransactionUpdate<Æ>,\n) => void\n\nexport const subscribeToTransaction = <Æ extends Æn>(\n\ttoken: TransactionToken<Æ>,\n\thandleUpdate: TransactionUpdateHandler<Æ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === null) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`ð subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`ð unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === null) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`ð subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`ð unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, Æn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<Æ extends Æn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<Æ>\n\toutput: ReturnType<Æ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<Æ extends Æn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<Æ>\n) => ReturnType<Æ>\n\nexport type Write<Æ extends Æn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<Æ>\n) => ReturnType<Æ>\n\nexport type TransactionOptions<Æ extends Æn> = {\n\tkey: string\n\tdo: Write<Æ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer Æ> ? Æ : never\n\nexport function transaction<Æ extends Æn>(\n\toptions: TransactionOptions<Æ>,\n): TransactionToken<Æ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<Æ extends Æn>(token: TransactionToken<Æ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<Æ>): ReturnType<Æ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
|