atom.io 0.16.1 → 0.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/dist/index.cjs +31 -14
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.js +31 -14
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +31 -14
- package/dist/index.cjs +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +17 -12
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.js +17 -12
- package/internal/dist/index.js.map +1 -1
- package/internal/src/mutable/tracker.ts +13 -11
- package/internal/src/set-state/set-atom.ts +7 -4
- package/internal/src/transaction/build-transaction.ts +1 -1
- package/package.json +2 -2
- package/realtime-client/dist/index.cjs +1 -0
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.js +1 -0
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/sync-server-action.ts +1 -0
- package/realtime-react/dist/index.cjs +2 -2
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.js +2 -2
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/use-server-action.ts +1 -1
- package/realtime-react/src/use-sync-server-action.ts +1 -1
- package/realtime-server/dist/index.cjs +19 -8
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +11 -4
- package/realtime-server/dist/index.js +19 -8
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/realtime-action-receiver.ts +4 -3
- package/realtime-server/src/realtime-action-synchronizer.ts +13 -1
- package/realtime-server/src/realtime-family-provider.ts +8 -4
- package/realtime-server/src/realtime-mutable-family-provider.ts +13 -17
- package/realtime-server/src/realtime-mutable-provider.ts +1 -0
- package/realtime-server/src/realtime-state-provider.ts +1 -0
- package/realtime-server/src/realtime-state-receiver.ts +1 -0
- package/src/logger.ts +15 -11
- package/src/transaction.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -64,8 +64,11 @@ function getState(token, store = Internal3__namespace.IMPLICIT.STORE) {
|
|
|
64
64
|
|
|
65
65
|
// src/logger.ts
|
|
66
66
|
var LOG_LEVELS = [`info`, `warn`, `error`];
|
|
67
|
-
var simpleLog = (logLevel) => (icon,
|
|
68
|
-
console[logLevel](
|
|
67
|
+
var simpleLog = (logLevel) => (icon, denomination, tokenKey, message, ...rest) => {
|
|
68
|
+
console[logLevel](
|
|
69
|
+
`${icon} ${denomination} "${tokenKey}" ${message}`,
|
|
70
|
+
...rest
|
|
71
|
+
);
|
|
69
72
|
};
|
|
70
73
|
var simpleLogger = {
|
|
71
74
|
error: simpleLog(`error`),
|
|
@@ -164,7 +167,7 @@ var undo = (timeline2) => {
|
|
|
164
167
|
function transaction(options) {
|
|
165
168
|
return Internal3.createTransaction(options, Internal3.IMPLICIT.STORE);
|
|
166
169
|
}
|
|
167
|
-
var runTransaction = (token, store = Internal3.IMPLICIT.STORE
|
|
170
|
+
var runTransaction = (token, id, store = Internal3.IMPLICIT.STORE) => (...parameters) => {
|
|
168
171
|
const tx = Internal3.withdraw(token, store);
|
|
169
172
|
if (tx) {
|
|
170
173
|
return tx.run(parameters, id);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/find-state.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/validators.ts"],"names":["IMPLICIT","Internal","createAtomFamily","createSelectorFamily","createStandaloneAtom","createStandaloneSelector","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,SAAO,qBAAqB,SAAS,SAAS,KAAK;AACpD;AAoFO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O,cAAc,KAAK,KAAK;AAAA,IACxD,KAAK;AACJ,aAAO,uBAAuB,OAAO,cAAc,KAAK,KAAK;AAAA,IAC9D,KAAK;AACJ,aAAO,oBAAoB,OAAO,cAAc,KAAK,KAAK;AAAA,EAC5D;AACD;;;AC3DA,SAAS,YAAAA,WAAU,kBAAAM,iBAAgB,cAAAC,mBAAkB;AA0B9C,IAAM,WAAW,CACvB,YACgC;AAChC,SAAOD,gBAAe,SAASN,UAAS,KAAK;AAC9C;AAEO,IAAM,OAAO,CAACQ,cAAuC;AAC3D,EAAAD,YAAW,QAAQC,WAAUR,UAAS,KAAK;AAC5C;AAEO,IAAM,OAAO,CAACQ,cAAuC;AAC3D,EAAAD,YAAW,QAAQC,WAAUR,UAAS,KAAK;AAC5C;;;AC3CA,SAAS,YAAAA,WAAU,qBAAAS,oBAAmB,YAAAC,iBAAgB;AAwE/C,SAAS,YACf,SACsB;AACtB,SAAOD,mBAAkB,SAAST,UAAS,KAAK;AACjD;AAEO,IAAM,iBACZ,CACC,OACA,QAAeA,UAAS,OACxB,OAED,IAAI,eAA6C;AAChD,QAAM,KAAKU,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,YAAY,EAAE;AAAA,EAC7B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD;;;AC9CM,SAAS,QACf,YACA,cACuD;AACvD,SAAO,WAAW,QAAQ,aAAa;AACxC;AA0BO,SAAS,UACf,QACA,cACmD;AAjFpD;AAkFC,SAAO,OAAO,UAAQ,kBAAa,WAAb,mBAAqB;AAC5C","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateAtomFamily,\n\tcreateStandaloneAtom,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken, RegularAtomToken } 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) | void\n\nexport type RegularAtomOptions<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<RegularAtomOptions<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: RegularAtomOptions<T>): RegularAtomToken<T>\nexport function atom(\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<any>,\n): AtomToken<any> {\n\treturn createStandaloneAtom(options, IMPLICIT.STORE)\n}\n\nexport type RegularAtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type RegularAtomFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => RegularAtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<RegularAtomToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type RegularAtomFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `atom_family`\n\t__T?: T\n\t__K?: K\n}\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& JsonInterface<T, J>\n\t& { \n\t\tkey: string\n\t\tdefault: (key: K) => T\n\t\teffects?: (key: K) => AtomEffect<T>[]\n\t\tmutable: true,\n\t}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& JsonInterface<T, J>\n\t& ((key: K) => MutableAtomToken<T, J>) \n\t& {\n\t\t\tkey: string\n\t\t\ttype: `mutable_atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<T, J>>\n\t\t\tinstall: (store: Store) => void\n\t\t\t__T?: T\n\t\t\t__J?: J\n\t\t\t__K?: K\n\t\t}\nexport type MutableAtomFamilyToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = {\n\tkey: string\n\ttype: `mutable_atom_family`\n\t__T?: T\n\t__J?: J\n\t__K?: K\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamily<T, K>\nexport type AtomFamilyToken<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamilyToken<T, K>\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: RegularAtomFamilyOptions<T, K>,\n): RegularAtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t| RegularAtomFamilyOptions<T, K>,\n): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadableToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlySelectorFamilyToken,\n\tReadonlySelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tWritableFamilyToken,\n\tWritableSelectorFamilyToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function findInStore(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n\tstore: Store,\n): ReadableToken<any> {\n\tconst familyKey = token.key\n\tconst family = store.families.get(familyKey)\n\tif (family === undefined) {\n\t\tthrow new Error(`Family ${familyKey} not found`)\n\t}\n\tconst state = family(key)\n\treturn state\n}\n\nexport function findState<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n\tKey extends K,\n>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritableSelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadonlySelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlySelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T>\nexport function findState(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n): ReadableToken<any> {\n\tconst state = findInStore(token, key, IMPLICIT.STORE)\n\treturn state\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n\t\"🚀\": `Performance measure`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `mutable_atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateSelectorFamily,\n\tcreateStandaloneSelector,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, WritableSelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type WritableSelectorOptions<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>(\n\toptions: WritableSelectorOptions<T>,\n): WritableSelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,\n): ReadonlySelectorToken<T> | WritableSelectorToken<T> {\n\treturn createStandaloneSelector(options, IMPLICIT.STORE)\n}\n\nexport type WritableSelectorFamilyOptions<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 WritableSelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => WritableSelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<WritableSelectorToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type WritableSelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `selector_family`\n\t__T?: T\n\t__K?: K\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\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `readonly_selector_family`\n\t__T?: T\n\t__K?: K\n}\n\nexport type SelectorFamily<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamily<T, K>\n\t| WritableSelectorFamily<T, K>\nexport type SelectorFamilyToken<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamilyToken<T, K>\n\t| WritableSelectorFamilyToken<T, K>\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: WritableSelectorFamilyOptions<T, K>,\n): WritableSelectorFamily<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:\n\t\t| ReadonlySelectorFamilyOptions<T, K>\n\t\t| WritableSelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | WritableSelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { WritableToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: WritableToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import type { Transceiver } from \"atom.io/internal\"\nimport {\n\tStore,\n\tcreateAtomFamily,\n\tcreateSelectorFamily,\n\tcreateStandaloneAtom,\n\tcreateStandaloneSelector,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tAtomToken,\n\tMutableAtomFamily,\n\tMutableAtomFamilyOptions,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tRegularAtomFamily,\n\tRegularAtomFamilyOptions,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tredo,\n\ttimeline,\n\tundo,\n} 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\tfunction _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>\n\t\tfunction _atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\t\t\toptions: MutableAtomOptions<T, J>,\n\t\t): MutableAtomToken<T, J>\n\t\tfunction _atom<T>(\n\t\t\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n\t\t): AtomToken<T> {\n\t\t\treturn createStandaloneAtom(options, s)\n\t\t}\n\t\tfunction _atomFamily<\n\t\t\tT extends Transceiver<any>,\n\t\t\tJ extends Json.Serializable,\n\t\t\tK extends Json.Serializable,\n\t\t>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions: RegularAtomFamilyOptions<T, K>,\n\t\t): RegularAtomFamily<T, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions:\n\t\t\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t\t\t| RegularAtomFamilyOptions<T, K>,\n\t\t): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.store = s\n\t\tthis.atom = _atom\n\t\tthis.atomFamily = _atomFamily\n\t\tthis.selector = (options) => createStandaloneSelector(options, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(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) => timeTravel(`undo`, token, s)\n\t\tthis.redo = (token) => timeTravel(`redo`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadableToken,\n\tTimelineManageable,\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 type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineManageable = AtomFamily<any, any> | AtomToken<any>\n\nexport type TimelineToken<_> = {\n\tkey: string\n\ttype: `timeline`\n\t__brand?: _\n}\n\nexport type TimelineOptions<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\tatoms: ManagedAtom[]\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<TimelineManageable>,\n\t) => boolean\n}\n\nexport type TimelineUpdate<ManagedAtom extends TimelineManageable> =\n\t| TimelineAtomUpdate<ManagedAtom>\n\t| TimelineSelectorUpdate<ManagedAtom>\n\t| TimelineTransactionUpdate\n\nexport const timeline = <ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n): TimelineToken<ManagedAtom> => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`redo`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`undo`, timeline, IMPLICIT.STORE)\n}\n","import type { EnvironmentData, Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tKeyedStateUpdate,\n\tReadonlySelectorToken,\n\tWritableToken,\n\tfindState,\n\tƒn,\n} from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdateContent =\n\t| KeyedStateUpdate<unknown>\n\t| TransactionUpdate<ƒn>\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tid: string\n\tupdates: TransactionUpdateContent[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n}>\nexport type TransactorsWithRunAndEnv = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n\trun: typeof runTransaction\n\tenv: () => EnvironmentData\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `find` | `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 Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRunAndEnv,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\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 createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(\n\t\ttoken: TransactionToken<ƒ>,\n\t\tstore: Store = IMPLICIT.STORE,\n\t\tid?: string,\n\t) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(parameters, id)\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 type {\n\tMutableAtomFamily,\n\tMutableAtomToken,\n\tReadableFamily,\n\tReadableToken,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tRegularAtomFamily,\n\tRegularAtomToken,\n\tWritableFamily,\n\tWritableSelectorFamily,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\n\nexport type TokenType<\n\tComparison extends ReadableFamily<any, any> | ReadableToken<any>,\n> = Comparison extends ReadableToken<infer RepresentedValue>\n\t? RepresentedValue\n\t: Comparison extends ReadableFamily<infer RepresentedValue, any>\n\t ? RepresentedValue\n\t : never\n\nexport function isToken<KnownToken extends RegularAtomToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends MutableAtomToken<any, any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<KnownToken>, any>\nexport function isToken<KnownToken extends WritableSelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadonlySelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>> {\n\treturn knownToken.key === unknownToken.key\n}\n\nexport function belongsTo<Family extends RegularAtomFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<Family>>\nexport function belongsTo<Family extends MutableAtomFamily<any, any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<Family>, any>\nexport function belongsTo<Family extends WritableSelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends WritableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>> {\n\treturn family.key === unknownToken.family?.key\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/find-state.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/validators.ts"],"names":["IMPLICIT","Internal","createAtomFamily","createSelectorFamily","createStandaloneAtom","createStandaloneSelector","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,SAAO,qBAAqB,SAAS,SAAS,KAAK;AACpD;AAoFO,SAAS,WACf,SAG6D;AAC7D,SAAO,iBAAiB,SAAS,SAAS,KAAK;AAChD;;;ACjIA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,KAAK;AACpC;AAAA,EACF;AACD;;;ACFA,SAAS,YAAAA,iBAAgB;AAGlB,SAAS,YACf,OACA,KACA,OACqB;AACrB,QAAM,YAAY,MAAM;AACxB,QAAM,SAAS,MAAM,SAAS,IAAI,SAAS;AAC3C,MAAI,WAAW,QAAW;AACzB,UAAM,IAAI,MAAM,UAAU,SAAS,YAAY;AAAA,EAChD;AACA,QAAM,QAAQ,OAAO,GAAG;AACxB,SAAO;AACR;AA4BO,SAAS,UACf,OACA,KACqB;AACrB,QAAM,QAAQ,YAAY,OAAO,KAAKA,UAAS,KAAK;AACpD,SAAO;AACR;;;AChEA,YAAYC,eAAc;AAInB,SAAS,SACf,OACA,QAAiC,mBAAS,OACtC;AAPL;AAQC,QAAM,SACL,KAAS,mBAAS,O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P,WAAO,GAAG,IAAI,YAAY,EAAE;AAAA,EAC7B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD;;;AC9CM,SAAS,QACf,YACA,cACuD;AACvD,SAAO,WAAW,QAAQ,aAAa;AACxC;AA0BO,SAAS,UACf,QACA,cACmD;AAjFpD;AAkFC,SAAO,OAAO,UAAQ,kBAAa,WAAb,mBAAqB;AAC5C","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateAtomFamily,\n\tcreateStandaloneAtom,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken, RegularAtomToken } 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) | void\n\nexport type RegularAtomOptions<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<RegularAtomOptions<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: RegularAtomOptions<T>): RegularAtomToken<T>\nexport function atom(\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<any>,\n): AtomToken<any> {\n\treturn createStandaloneAtom(options, IMPLICIT.STORE)\n}\n\nexport type RegularAtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type RegularAtomFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => RegularAtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<RegularAtomToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type RegularAtomFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `atom_family`\n\t__T?: T\n\t__K?: K\n}\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& JsonInterface<T, J>\n\t& { \n\t\tkey: string\n\t\tdefault: (key: K) => T\n\t\teffects?: (key: K) => AtomEffect<T>[]\n\t\tmutable: true,\n\t}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& JsonInterface<T, J>\n\t& ((key: K) => MutableAtomToken<T, J>) \n\t& {\n\t\t\tkey: string\n\t\t\ttype: `mutable_atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<T, J>>\n\t\t\tinstall: (store: Store) => void\n\t\t\t__T?: T\n\t\t\t__J?: J\n\t\t\t__K?: K\n\t\t}\nexport type MutableAtomFamilyToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = {\n\tkey: string\n\ttype: `mutable_atom_family`\n\t__T?: T\n\t__J?: J\n\t__K?: K\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamily<T, K>\nexport type AtomFamilyToken<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamilyToken<T, K>\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: RegularAtomFamilyOptions<T, K>,\n): RegularAtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t| RegularAtomFamilyOptions<T, K>,\n): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadableToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlySelectorFamilyToken,\n\tReadonlySelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tWritableFamilyToken,\n\tWritableSelectorFamilyToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function findInStore(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n\tstore: Store,\n): ReadableToken<any> {\n\tconst familyKey = token.key\n\tconst family = store.families.get(familyKey)\n\tif (family === undefined) {\n\t\tthrow new Error(`Family ${familyKey} not found`)\n\t}\n\tconst state = family(key)\n\treturn state\n}\n\nexport function findState<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n\tKey extends K,\n>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritableSelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadonlySelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlySelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T>\nexport function findState(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n): ReadableToken<any> {\n\tconst state = findInStore(token, key, IMPLICIT.STORE)\n\treturn state\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n\t\"🚀\": `Performance measure`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\nexport type TokenDenomination =\n\t| `atom`\n\t| `mutable_atom`\n\t| `readonly_selector`\n\t| `selector`\n\t| `state`\n\t| `timeline`\n\t| `transaction`\n\t| `unknown`\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\tdenomination: TokenDenomination,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, denomination, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](\n\t\t\t`${icon} ${denomination} \"${tokenKey}\" ${message}`,\n\t\t\t...rest,\n\t\t)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateSelectorFamily,\n\tcreateStandaloneSelector,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, WritableSelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type WritableSelectorOptions<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>(\n\toptions: WritableSelectorOptions<T>,\n): WritableSelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,\n): ReadonlySelectorToken<T> | WritableSelectorToken<T> {\n\treturn createStandaloneSelector(options, IMPLICIT.STORE)\n}\n\nexport type WritableSelectorFamilyOptions<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 WritableSelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => WritableSelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<WritableSelectorToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type WritableSelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `selector_family`\n\t__T?: T\n\t__K?: K\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\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `readonly_selector_family`\n\t__T?: T\n\t__K?: K\n}\n\nexport type SelectorFamily<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamily<T, K>\n\t| WritableSelectorFamily<T, K>\nexport type SelectorFamilyToken<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamilyToken<T, K>\n\t| WritableSelectorFamilyToken<T, K>\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: WritableSelectorFamilyOptions<T, K>,\n): WritableSelectorFamily<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:\n\t\t| ReadonlySelectorFamilyOptions<T, K>\n\t\t| WritableSelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | WritableSelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { WritableToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: WritableToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import type { Transceiver } from \"atom.io/internal\"\nimport {\n\tStore,\n\tcreateAtomFamily,\n\tcreateSelectorFamily,\n\tcreateStandaloneAtom,\n\tcreateStandaloneSelector,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tAtomToken,\n\tMutableAtomFamily,\n\tMutableAtomFamilyOptions,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tRegularAtomFamily,\n\tRegularAtomFamilyOptions,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tredo,\n\ttimeline,\n\tundo,\n} 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\tfunction _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>\n\t\tfunction _atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\t\t\toptions: MutableAtomOptions<T, J>,\n\t\t): MutableAtomToken<T, J>\n\t\tfunction _atom<T>(\n\t\t\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n\t\t): AtomToken<T> {\n\t\t\treturn createStandaloneAtom(options, s)\n\t\t}\n\t\tfunction _atomFamily<\n\t\t\tT extends Transceiver<any>,\n\t\t\tJ extends Json.Serializable,\n\t\t\tK extends Json.Serializable,\n\t\t>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions: RegularAtomFamilyOptions<T, K>,\n\t\t): RegularAtomFamily<T, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions:\n\t\t\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t\t\t| RegularAtomFamilyOptions<T, K>,\n\t\t): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.store = s\n\t\tthis.atom = _atom\n\t\tthis.atomFamily = _atomFamily\n\t\tthis.selector = (options) => createStandaloneSelector(options, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(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) => timeTravel(`undo`, token, s)\n\t\tthis.redo = (token) => timeTravel(`redo`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadableToken,\n\tTimelineManageable,\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 type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineManageable = AtomFamily<any, any> | AtomToken<any>\n\nexport type TimelineToken<_> = {\n\tkey: string\n\ttype: `timeline`\n\t__brand?: _\n}\n\nexport type TimelineOptions<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\tatoms: ManagedAtom[]\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<TimelineManageable>,\n\t) => boolean\n}\n\nexport type TimelineUpdate<ManagedAtom extends TimelineManageable> =\n\t| TimelineAtomUpdate<ManagedAtom>\n\t| TimelineSelectorUpdate<ManagedAtom>\n\t| TimelineTransactionUpdate\n\nexport const timeline = <ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n): TimelineToken<ManagedAtom> => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`redo`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`undo`, timeline, IMPLICIT.STORE)\n}\n","import type { EnvironmentData, Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tKeyedStateUpdate,\n\tReadonlySelectorToken,\n\tWritableToken,\n\tfindState,\n\tƒn,\n} from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdateContent =\n\t| KeyedStateUpdate<unknown>\n\t| TransactionUpdate<ƒn>\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tid: string\n\tupdates: TransactionUpdateContent[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n}>\nexport type TransactorsWithRunAndEnv = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n\trun: typeof runTransaction\n\tenv: () => EnvironmentData\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `find` | `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 Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRunAndEnv,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\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 createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(\n\t\ttoken: TransactionToken<ƒ>,\n\t\tid?: string,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(parameters, id)\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 type {\n\tMutableAtomFamily,\n\tMutableAtomToken,\n\tReadableFamily,\n\tReadableToken,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tRegularAtomFamily,\n\tRegularAtomToken,\n\tWritableFamily,\n\tWritableSelectorFamily,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\n\nexport type TokenType<\n\tComparison extends ReadableFamily<any, any> | ReadableToken<any>,\n> = Comparison extends ReadableToken<infer RepresentedValue>\n\t? RepresentedValue\n\t: Comparison extends ReadableFamily<infer RepresentedValue, any>\n\t ? RepresentedValue\n\t : never\n\nexport function isToken<KnownToken extends RegularAtomToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends MutableAtomToken<any, any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<KnownToken>, any>\nexport function isToken<KnownToken extends WritableSelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadonlySelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>> {\n\treturn knownToken.key === unknownToken.key\n}\n\nexport function belongsTo<Family extends RegularAtomFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<Family>>\nexport function belongsTo<Family extends MutableAtomFamily<any, any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<Family>, any>\nexport function belongsTo<Family extends WritableSelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends WritableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>> {\n\treturn family.key === unknownToken.family?.key\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ type TransactionOptions<ƒ extends ƒn> = {
|
|
|
103
103
|
};
|
|
104
104
|
type TransactionIO<Token extends TransactionToken<any>> = Token extends TransactionToken<infer ƒ> ? ƒ : never;
|
|
105
105
|
declare function transaction<ƒ extends ƒn>(options: TransactionOptions<ƒ>): TransactionToken<ƒ>;
|
|
106
|
-
declare const runTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>,
|
|
106
|
+
declare const runTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, id?: string, store?: Store) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
107
107
|
|
|
108
108
|
type WritableSelectorOptions<T> = {
|
|
109
109
|
key: string;
|
|
@@ -211,9 +211,10 @@ declare const LoggerIconDictionary: {
|
|
|
211
211
|
readonly "\uD83D\uDE80": "Performance measure";
|
|
212
212
|
};
|
|
213
213
|
type LoggerIcon = keyof typeof LoggerIconDictionary;
|
|
214
|
+
type TokenDenomination = `atom` | `mutable_atom` | `readonly_selector` | `selector` | `state` | `timeline` | `transaction` | `unknown`;
|
|
214
215
|
declare const LOG_LEVELS: readonly ["info", "warn", "error"];
|
|
215
216
|
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
216
|
-
type LogFn = (icon: LoggerIcon,
|
|
217
|
+
type LogFn = (icon: LoggerIcon, denomination: TokenDenomination, tokenKey: string, message: string, ...rest: unknown[]) => void;
|
|
217
218
|
type LogFilter = (...params: Parameters<LogFn>) => boolean;
|
|
218
219
|
type Logger = Record<LogLevel, LogFn>;
|
|
219
220
|
declare const simpleLog: (logLevel: keyof Logger) => LogFn;
|
|
@@ -329,4 +330,4 @@ type FamilyMetadata = {
|
|
|
329
330
|
subKey: string;
|
|
330
331
|
};
|
|
331
332
|
|
|
332
|
-
export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, dispose, findInStore, findState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo, type ƒn };
|
|
333
|
+
export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, dispose, findInStore, findState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo, type ƒn };
|
package/dist/index.js
CHANGED
|
@@ -43,8 +43,11 @@ function getState(token, store = Internal3.IMPLICIT.STORE) {
|
|
|
43
43
|
|
|
44
44
|
// src/logger.ts
|
|
45
45
|
var LOG_LEVELS = [`info`, `warn`, `error`];
|
|
46
|
-
var simpleLog = (logLevel) => (icon,
|
|
47
|
-
console[logLevel](
|
|
46
|
+
var simpleLog = (logLevel) => (icon, denomination, tokenKey, message, ...rest) => {
|
|
47
|
+
console[logLevel](
|
|
48
|
+
`${icon} ${denomination} "${tokenKey}" ${message}`,
|
|
49
|
+
...rest
|
|
50
|
+
);
|
|
48
51
|
};
|
|
49
52
|
var simpleLogger = {
|
|
50
53
|
error: simpleLog(`error`),
|
|
@@ -143,7 +146,7 @@ var undo = (timeline2) => {
|
|
|
143
146
|
function transaction(options) {
|
|
144
147
|
return createTransaction(options, IMPLICIT.STORE);
|
|
145
148
|
}
|
|
146
|
-
var runTransaction = (token, store = IMPLICIT.STORE
|
|
149
|
+
var runTransaction = (token, id, store = IMPLICIT.STORE) => (...parameters) => {
|
|
147
150
|
const tx = withdraw(token, store);
|
|
148
151
|
if (tx) {
|
|
149
152
|
return tx.run(parameters, id);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/find-state.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/validators.ts"],"names":["IMPLICIT","Internal","createAtomFamily","createSelectorFamily","createStandaloneAtom","createStandaloneSelector","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,SAAO,qBAAqB,SAAS,SAAS,KAAK;AACpD;AAoFO,SAAS,WACf,SAG6D;AAC7D,SAAO,iBAAiB,SAAS,SAAS,KAAK;AAChD;;;ACjIA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MA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B,YACgC;AAChC,SAAOD,gBAAe,SAASN,UAAS,KAAK;AAC9C;AAEO,IAAM,OAAO,CAACQ,cAAuC;AAC3D,EAAAD,YAAW,QAAQC,WAAUR,UAAS,KAAK;AAC5C;AAEO,IAAM,OAAO,CAACQ,cAAuC;AAC3D,EAAAD,YAAW,QAAQC,WAAUR,UAAS,KAAK;AAC5C;;;AC3CA,SAAS,YAAAA,WAAU,qBAAAS,oBAAmB,YAAAC,iBAAgB;AAwE/C,SAAS,YACf,SACsB;AACtB,SAAOD,mBAAkB,SAAST,UAAS,KAAK;AACjD;AAEO,IAAM,iBACZ,CACC,OACA,QAAeA,UAAS,OACxB,OAED,IAAI,eAA6C;AAChD,QAAM,KAAKU,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,YAAY,EAAE;AAAA,EAC7B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD;;;AC9CM,SAAS,QACf,YACA,cACuD;AACvD,SAAO,WAAW,QAAQ,aAAa;AACxC;AA0BO,SAAS,UACf,QACA,cACmD;AAjFpD;AAkFC,SAAO,OAAO,UAAQ,kBAAa,WAAb,mBAAqB;AAC5C","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateAtomFamily,\n\tcreateStandaloneAtom,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken, RegularAtomToken } 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) | void\n\nexport type RegularAtomOptions<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<RegularAtomOptions<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: RegularAtomOptions<T>): RegularAtomToken<T>\nexport function atom(\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<any>,\n): AtomToken<any> {\n\treturn createStandaloneAtom(options, IMPLICIT.STORE)\n}\n\nexport type RegularAtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type RegularAtomFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => RegularAtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<RegularAtomToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type RegularAtomFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `atom_family`\n\t__T?: T\n\t__K?: K\n}\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& JsonInterface<T, J>\n\t& { \n\t\tkey: string\n\t\tdefault: (key: K) => T\n\t\teffects?: (key: K) => AtomEffect<T>[]\n\t\tmutable: true,\n\t}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& JsonInterface<T, J>\n\t& ((key: K) => MutableAtomToken<T, J>) \n\t& {\n\t\t\tkey: string\n\t\t\ttype: `mutable_atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<T, J>>\n\t\t\tinstall: (store: Store) => void\n\t\t\t__T?: T\n\t\t\t__J?: J\n\t\t\t__K?: K\n\t\t}\nexport type MutableAtomFamilyToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = {\n\tkey: string\n\ttype: `mutable_atom_family`\n\t__T?: T\n\t__J?: J\n\t__K?: K\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamily<T, K>\nexport type AtomFamilyToken<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamilyToken<T, K>\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: RegularAtomFamilyOptions<T, K>,\n): RegularAtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t| RegularAtomFamilyOptions<T, K>,\n): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadableToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlySelectorFamilyToken,\n\tReadonlySelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tWritableFamilyToken,\n\tWritableSelectorFamilyToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function findInStore(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n\tstore: Store,\n): ReadableToken<any> {\n\tconst familyKey = token.key\n\tconst family = store.families.get(familyKey)\n\tif (family === undefined) {\n\t\tthrow new Error(`Family ${familyKey} not found`)\n\t}\n\tconst state = family(key)\n\treturn state\n}\n\nexport function findState<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n\tKey extends K,\n>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritableSelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadonlySelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlySelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T>\nexport function findState(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n): ReadableToken<any> {\n\tconst state = findInStore(token, key, IMPLICIT.STORE)\n\treturn state\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n\t\"🚀\": `Performance measure`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `mutable_atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateSelectorFamily,\n\tcreateStandaloneSelector,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, WritableSelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type WritableSelectorOptions<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>(\n\toptions: WritableSelectorOptions<T>,\n): WritableSelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,\n): ReadonlySelectorToken<T> | WritableSelectorToken<T> {\n\treturn createStandaloneSelector(options, IMPLICIT.STORE)\n}\n\nexport type WritableSelectorFamilyOptions<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 WritableSelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => WritableSelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<WritableSelectorToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type WritableSelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `selector_family`\n\t__T?: T\n\t__K?: K\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\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `readonly_selector_family`\n\t__T?: T\n\t__K?: K\n}\n\nexport type SelectorFamily<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamily<T, K>\n\t| WritableSelectorFamily<T, K>\nexport type SelectorFamilyToken<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamilyToken<T, K>\n\t| WritableSelectorFamilyToken<T, K>\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: WritableSelectorFamilyOptions<T, K>,\n): WritableSelectorFamily<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:\n\t\t| ReadonlySelectorFamilyOptions<T, K>\n\t\t| WritableSelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | WritableSelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { WritableToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: WritableToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import type { Transceiver } from \"atom.io/internal\"\nimport {\n\tStore,\n\tcreateAtomFamily,\n\tcreateSelectorFamily,\n\tcreateStandaloneAtom,\n\tcreateStandaloneSelector,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tAtomToken,\n\tMutableAtomFamily,\n\tMutableAtomFamilyOptions,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tRegularAtomFamily,\n\tRegularAtomFamilyOptions,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tredo,\n\ttimeline,\n\tundo,\n} 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\tfunction _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>\n\t\tfunction _atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\t\t\toptions: MutableAtomOptions<T, J>,\n\t\t): MutableAtomToken<T, J>\n\t\tfunction _atom<T>(\n\t\t\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n\t\t): AtomToken<T> {\n\t\t\treturn createStandaloneAtom(options, s)\n\t\t}\n\t\tfunction _atomFamily<\n\t\t\tT extends Transceiver<any>,\n\t\t\tJ extends Json.Serializable,\n\t\t\tK extends Json.Serializable,\n\t\t>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions: RegularAtomFamilyOptions<T, K>,\n\t\t): RegularAtomFamily<T, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions:\n\t\t\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t\t\t| RegularAtomFamilyOptions<T, K>,\n\t\t): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.store = s\n\t\tthis.atom = _atom\n\t\tthis.atomFamily = _atomFamily\n\t\tthis.selector = (options) => createStandaloneSelector(options, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(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) => timeTravel(`undo`, token, s)\n\t\tthis.redo = (token) => timeTravel(`redo`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadableToken,\n\tTimelineManageable,\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 type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineManageable = AtomFamily<any, any> | AtomToken<any>\n\nexport type TimelineToken<_> = {\n\tkey: string\n\ttype: `timeline`\n\t__brand?: _\n}\n\nexport type TimelineOptions<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\tatoms: ManagedAtom[]\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<TimelineManageable>,\n\t) => boolean\n}\n\nexport type TimelineUpdate<ManagedAtom extends TimelineManageable> =\n\t| TimelineAtomUpdate<ManagedAtom>\n\t| TimelineSelectorUpdate<ManagedAtom>\n\t| TimelineTransactionUpdate\n\nexport const timeline = <ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n): TimelineToken<ManagedAtom> => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`redo`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`undo`, timeline, IMPLICIT.STORE)\n}\n","import type { EnvironmentData, Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tKeyedStateUpdate,\n\tReadonlySelectorToken,\n\tWritableToken,\n\tfindState,\n\tƒn,\n} from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdateContent =\n\t| KeyedStateUpdate<unknown>\n\t| TransactionUpdate<ƒn>\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tid: string\n\tupdates: TransactionUpdateContent[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n}>\nexport type TransactorsWithRunAndEnv = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n\trun: typeof runTransaction\n\tenv: () => EnvironmentData\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `find` | `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 Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRunAndEnv,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\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 createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(\n\t\ttoken: TransactionToken<ƒ>,\n\t\tstore: Store = IMPLICIT.STORE,\n\t\tid?: string,\n\t) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(parameters, id)\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 type {\n\tMutableAtomFamily,\n\tMutableAtomToken,\n\tReadableFamily,\n\tReadableToken,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tRegularAtomFamily,\n\tRegularAtomToken,\n\tWritableFamily,\n\tWritableSelectorFamily,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\n\nexport type TokenType<\n\tComparison extends ReadableFamily<any, any> | ReadableToken<any>,\n> = Comparison extends ReadableToken<infer RepresentedValue>\n\t? RepresentedValue\n\t: Comparison extends ReadableFamily<infer RepresentedValue, any>\n\t ? RepresentedValue\n\t : never\n\nexport function isToken<KnownToken extends RegularAtomToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends MutableAtomToken<any, any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<KnownToken>, any>\nexport function isToken<KnownToken extends WritableSelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadonlySelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>> {\n\treturn knownToken.key === unknownToken.key\n}\n\nexport function belongsTo<Family extends RegularAtomFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<Family>>\nexport function belongsTo<Family extends MutableAtomFamily<any, any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<Family>, any>\nexport function belongsTo<Family extends WritableSelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends WritableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>> {\n\treturn family.key === unknownToken.family?.key\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/find-state.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/validators.ts"],"names":["IMPLICIT","Internal","createAtomFamily","createSelectorFamily","createStandaloneAtom","createStandaloneSelector","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,SAAO,qBAAqB,SAAS,SAAS,KAAK;AACpD;AAoFO,SAAS,WACf,SAG6D;AAC7D,SAAO,iBAAiB,SAAS,SAAS,KAAK;AAChD;;;ACjIA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,KAAK;AACpC;AAAA,EACF;AACD;;;ACFA,SAAS,YAAAA,iBAAgB;AAGlB,SAAS,YACf,OACA,KACA,OACqB;AACrB,QAAM,YAAY,MAAM;AACxB,QAAM,SAAS,MAAM,SAAS,IAAI,SAAS;AAC3C,MAAI,WAAW,QAAW;AACzB,UAAM,IAAI,MAAM,UAAU,SAAS,YAAY;AAAA,EAChD;AACA,QAAM,QAAQ,OAAO,GAAG;AACxB,SAAO;AACR;AA4BO,SAAS,UACf,OACA,KACqB;AACrB,QAAM,QAAQ,YAAY,OAAO,KAAKA,UAAS,KAAK;AACpD,SAAO;AACR;;;AChEA,YAAYC,eAAc;AAInB,SAAS,SACf,OACA,QAAiC,mBAAS,OACtC;AAPL;AAQC,QAAM,SACL,KAAS,mBAAS,OAAO,KAAK,MAA9B,YACS,kCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAa,wBAAc,OAAO,KAAK;AAAA,EAC9C;AACA,SAAgB,6BAAmB,OAAO,KAAK;AAChD;;;ACoCO,IAAM,aAAa,CAAC,QAAQ,QAAQ,OAAO;AAc3C,IAAM,YACZ,CAAC,aACD,CAAC,MAAM,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FC,SAAO,OAAO,UAAQ,kBAAa,WAAb,mBAAqB;AAC5C","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateAtomFamily,\n\tcreateStandaloneAtom,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken, RegularAtomToken } 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) | void\n\nexport type RegularAtomOptions<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<RegularAtomOptions<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: RegularAtomOptions<T>): RegularAtomToken<T>\nexport function atom(\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<any>,\n): AtomToken<any> {\n\treturn createStandaloneAtom(options, IMPLICIT.STORE)\n}\n\nexport type RegularAtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type RegularAtomFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => RegularAtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<RegularAtomToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type RegularAtomFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `atom_family`\n\t__T?: T\n\t__K?: K\n}\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& JsonInterface<T, J>\n\t& { \n\t\tkey: string\n\t\tdefault: (key: K) => T\n\t\teffects?: (key: K) => AtomEffect<T>[]\n\t\tmutable: true,\n\t}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& JsonInterface<T, J>\n\t& ((key: K) => MutableAtomToken<T, J>) \n\t& {\n\t\t\tkey: string\n\t\t\ttype: `mutable_atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<T, J>>\n\t\t\tinstall: (store: Store) => void\n\t\t\t__T?: T\n\t\t\t__J?: J\n\t\t\t__K?: K\n\t\t}\nexport type MutableAtomFamilyToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = {\n\tkey: string\n\ttype: `mutable_atom_family`\n\t__T?: T\n\t__J?: J\n\t__K?: K\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamily<T, K>\nexport type AtomFamilyToken<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamilyToken<T, K>\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: RegularAtomFamilyOptions<T, K>,\n): RegularAtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t| RegularAtomFamilyOptions<T, K>,\n): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadableToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlySelectorFamilyToken,\n\tReadonlySelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tWritableFamilyToken,\n\tWritableSelectorFamilyToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function findInStore(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n\tstore: Store,\n): ReadableToken<any> {\n\tconst familyKey = token.key\n\tconst family = store.families.get(familyKey)\n\tif (family === undefined) {\n\t\tthrow new Error(`Family ${familyKey} not found`)\n\t}\n\tconst state = family(key)\n\treturn state\n}\n\nexport function findState<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n\tKey extends K,\n>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritableSelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadonlySelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlySelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T>\nexport function findState(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n): ReadableToken<any> {\n\tconst state = findInStore(token, key, IMPLICIT.STORE)\n\treturn state\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n\t\"🚀\": `Performance measure`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\nexport type TokenDenomination =\n\t| `atom`\n\t| `mutable_atom`\n\t| `readonly_selector`\n\t| `selector`\n\t| `state`\n\t| `timeline`\n\t| `transaction`\n\t| `unknown`\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\tdenomination: TokenDenomination,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, denomination, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](\n\t\t\t`${icon} ${denomination} \"${tokenKey}\" ${message}`,\n\t\t\t...rest,\n\t\t)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateSelectorFamily,\n\tcreateStandaloneSelector,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, WritableSelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type WritableSelectorOptions<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>(\n\toptions: WritableSelectorOptions<T>,\n): WritableSelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,\n): ReadonlySelectorToken<T> | WritableSelectorToken<T> {\n\treturn createStandaloneSelector(options, IMPLICIT.STORE)\n}\n\nexport type WritableSelectorFamilyOptions<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 WritableSelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => WritableSelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<WritableSelectorToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type WritableSelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `selector_family`\n\t__T?: T\n\t__K?: K\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\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `readonly_selector_family`\n\t__T?: T\n\t__K?: K\n}\n\nexport type SelectorFamily<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamily<T, K>\n\t| WritableSelectorFamily<T, K>\nexport type SelectorFamilyToken<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamilyToken<T, K>\n\t| WritableSelectorFamilyToken<T, K>\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: WritableSelectorFamilyOptions<T, K>,\n): WritableSelectorFamily<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:\n\t\t| ReadonlySelectorFamilyOptions<T, K>\n\t\t| WritableSelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | WritableSelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { WritableToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: WritableToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import type { Transceiver } from \"atom.io/internal\"\nimport {\n\tStore,\n\tcreateAtomFamily,\n\tcreateSelectorFamily,\n\tcreateStandaloneAtom,\n\tcreateStandaloneSelector,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tAtomToken,\n\tMutableAtomFamily,\n\tMutableAtomFamilyOptions,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tRegularAtomFamily,\n\tRegularAtomFamilyOptions,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tredo,\n\ttimeline,\n\tundo,\n} 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\tfunction _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>\n\t\tfunction _atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\t\t\toptions: MutableAtomOptions<T, J>,\n\t\t): MutableAtomToken<T, J>\n\t\tfunction _atom<T>(\n\t\t\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n\t\t): AtomToken<T> {\n\t\t\treturn createStandaloneAtom(options, s)\n\t\t}\n\t\tfunction _atomFamily<\n\t\t\tT extends Transceiver<any>,\n\t\t\tJ extends Json.Serializable,\n\t\t\tK extends Json.Serializable,\n\t\t>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions: RegularAtomFamilyOptions<T, K>,\n\t\t): RegularAtomFamily<T, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions:\n\t\t\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t\t\t| RegularAtomFamilyOptions<T, K>,\n\t\t): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.store = s\n\t\tthis.atom = _atom\n\t\tthis.atomFamily = _atomFamily\n\t\tthis.selector = (options) => createStandaloneSelector(options, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(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) => timeTravel(`undo`, token, s)\n\t\tthis.redo = (token) => timeTravel(`redo`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadableToken,\n\tTimelineManageable,\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 type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineManageable = AtomFamily<any, any> | AtomToken<any>\n\nexport type TimelineToken<_> = {\n\tkey: string\n\ttype: `timeline`\n\t__brand?: _\n}\n\nexport type TimelineOptions<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\tatoms: ManagedAtom[]\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<TimelineManageable>,\n\t) => boolean\n}\n\nexport type TimelineUpdate<ManagedAtom extends TimelineManageable> =\n\t| TimelineAtomUpdate<ManagedAtom>\n\t| TimelineSelectorUpdate<ManagedAtom>\n\t| TimelineTransactionUpdate\n\nexport const timeline = <ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n): TimelineToken<ManagedAtom> => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`redo`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`undo`, timeline, IMPLICIT.STORE)\n}\n","import type { EnvironmentData, Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tKeyedStateUpdate,\n\tReadonlySelectorToken,\n\tWritableToken,\n\tfindState,\n\tƒn,\n} from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdateContent =\n\t| KeyedStateUpdate<unknown>\n\t| TransactionUpdate<ƒn>\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tid: string\n\tupdates: TransactionUpdateContent[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n}>\nexport type TransactorsWithRunAndEnv = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n\trun: typeof runTransaction\n\tenv: () => EnvironmentData\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `find` | `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 Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRunAndEnv,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\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 createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(\n\t\ttoken: TransactionToken<ƒ>,\n\t\tid?: string,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(parameters, id)\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 type {\n\tMutableAtomFamily,\n\tMutableAtomToken,\n\tReadableFamily,\n\tReadableToken,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tRegularAtomFamily,\n\tRegularAtomToken,\n\tWritableFamily,\n\tWritableSelectorFamily,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\n\nexport type TokenType<\n\tComparison extends ReadableFamily<any, any> | ReadableToken<any>,\n> = Comparison extends ReadableToken<infer RepresentedValue>\n\t? RepresentedValue\n\t: Comparison extends ReadableFamily<infer RepresentedValue, any>\n\t ? RepresentedValue\n\t : never\n\nexport function isToken<KnownToken extends RegularAtomToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends MutableAtomToken<any, any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<KnownToken>, any>\nexport function isToken<KnownToken extends WritableSelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadonlySelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>> {\n\treturn knownToken.key === unknownToken.key\n}\n\nexport function belongsTo<Family extends RegularAtomFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<Family>>\nexport function belongsTo<Family extends MutableAtomFamily<any, any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<Family>, any>\nexport function belongsTo<Family extends WritableSelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends WritableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>> {\n\treturn family.key === unknownToken.family?.key\n}\n"]}
|
package/internal/dist/index.cjs
CHANGED
|
@@ -781,11 +781,14 @@ var setAtom = (atom, next, target) => {
|
|
|
781
781
|
const update = { oldValue, newValue };
|
|
782
782
|
if (target.transactionMeta === null) {
|
|
783
783
|
emitUpdate(atom, update, target);
|
|
784
|
-
} else if (target.
|
|
785
|
-
|
|
786
|
-
|
|
784
|
+
} else if (target.parent) {
|
|
785
|
+
if (target.on.transactionApplying.state === null) {
|
|
786
|
+
stowUpdate(atom, update, target);
|
|
787
|
+
} else if (atom.key.startsWith(`*`)) {
|
|
787
788
|
const mutableKey = atom.key.slice(1);
|
|
788
|
-
const
|
|
789
|
+
const mutableAtom = target.atoms.get(mutableKey);
|
|
790
|
+
let mutable = target.valueMap.get(mutableKey);
|
|
791
|
+
mutable = copyMutableIfWithinTransaction(mutable, mutableAtom, target);
|
|
789
792
|
mutable.do(update.newValue);
|
|
790
793
|
}
|
|
791
794
|
}
|
|
@@ -1206,6 +1209,7 @@ var Tracker = class {
|
|
|
1206
1209
|
return latestUpdateState;
|
|
1207
1210
|
}
|
|
1208
1211
|
observeCore(mutableState, latestUpdateState, store) {
|
|
1212
|
+
const subscriptionKey = `tracker:${store.config.name}:${store.transactionMeta === null ? `main` : store.transactionMeta.update.key}:${mutableState.key}`;
|
|
1209
1213
|
const originalInnerValue = atom_io.getState(mutableState, store);
|
|
1210
1214
|
const target = newest(store);
|
|
1211
1215
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
@@ -1213,7 +1217,7 @@ var Tracker = class {
|
|
|
1213
1217
|
(update) => {
|
|
1214
1218
|
if (target.operation.open) {
|
|
1215
1219
|
const unsubscribe = target.on.operationClose.subscribe(
|
|
1216
|
-
|
|
1220
|
+
subscriptionKey,
|
|
1217
1221
|
() => {
|
|
1218
1222
|
unsubscribe();
|
|
1219
1223
|
atom_io.setState(latestUpdateState, update, target);
|
|
@@ -1232,11 +1236,11 @@ var Tracker = class {
|
|
|
1232
1236
|
this.unsubscribeFromInnerValue();
|
|
1233
1237
|
const target2 = newest(store);
|
|
1234
1238
|
this.unsubscribeFromInnerValue = update.newValue.subscribe(
|
|
1235
|
-
|
|
1239
|
+
subscriptionKey,
|
|
1236
1240
|
(update2) => {
|
|
1237
1241
|
if (target2.operation.open) {
|
|
1238
1242
|
const unsubscribe = target2.on.operationClose.subscribe(
|
|
1239
|
-
|
|
1243
|
+
subscriptionKey,
|
|
1240
1244
|
() => {
|
|
1241
1245
|
unsubscribe();
|
|
1242
1246
|
atom_io.setState(latestUpdateState, update2, target2);
|
|
@@ -1250,11 +1254,12 @@ var Tracker = class {
|
|
|
1250
1254
|
);
|
|
1251
1255
|
}
|
|
1252
1256
|
},
|
|
1253
|
-
|
|
1257
|
+
subscriptionKey,
|
|
1254
1258
|
store
|
|
1255
1259
|
);
|
|
1256
1260
|
}
|
|
1257
1261
|
updateCore(mutableState, latestUpdateState, store) {
|
|
1262
|
+
const subscriptionKey = `tracker:${store.config.name}:${store.transactionMeta === null ? `main` : store.transactionMeta.update.key}:${mutableState.key}`;
|
|
1258
1263
|
subscribeToState(
|
|
1259
1264
|
latestUpdateState,
|
|
1260
1265
|
({ newValue, oldValue }) => {
|
|
@@ -1281,14 +1286,14 @@ var Tracker = class {
|
|
|
1281
1286
|
store
|
|
1282
1287
|
);
|
|
1283
1288
|
},
|
|
1284
|
-
|
|
1289
|
+
subscriptionKey,
|
|
1285
1290
|
store
|
|
1286
1291
|
);
|
|
1287
1292
|
return;
|
|
1288
1293
|
}
|
|
1289
1294
|
}
|
|
1290
1295
|
const unsubscribe = store.on.operationClose.subscribe(
|
|
1291
|
-
|
|
1296
|
+
subscriptionKey,
|
|
1292
1297
|
() => {
|
|
1293
1298
|
unsubscribe();
|
|
1294
1299
|
const mutable = atom_io.getState(mutableState, store);
|
|
@@ -1304,7 +1309,7 @@ var Tracker = class {
|
|
|
1304
1309
|
}
|
|
1305
1310
|
);
|
|
1306
1311
|
},
|
|
1307
|
-
|
|
1312
|
+
subscriptionKey,
|
|
1308
1313
|
store
|
|
1309
1314
|
);
|
|
1310
1315
|
}
|
|
@@ -2314,7 +2319,7 @@ var buildTransaction = (key, params, store, id) => {
|
|
|
2314
2319
|
transactors: {
|
|
2315
2320
|
get: (token) => atom_io.getState(token, child),
|
|
2316
2321
|
set: (token, value) => atom_io.setState(token, value, child),
|
|
2317
|
-
run: (token) => atom_io.runTransaction(token, child),
|
|
2322
|
+
run: (token, id2) => atom_io.runTransaction(token, id2, child),
|
|
2318
2323
|
find: (token, key2) => atom_io.findInStore(token, key2, child),
|
|
2319
2324
|
env: () => getEnvironmentData(child)
|
|
2320
2325
|
}
|