atom.io 0.9.7 → 0.9.9

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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as Internal from 'atom.io/internal';
2
- import { Transceiver, Subject, Store, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
2
+ import { Transceiver, Subject, Store, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
3
3
  import { Json, JsonInterface } from 'atom.io/json';
4
4
 
5
5
  type Effectors<T> = {
@@ -150,6 +150,7 @@ type TimelineToken = {
150
150
  type TimelineOptions = {
151
151
  key: string;
152
152
  atoms: (AtomFamily<any, any> | AtomToken<any>)[];
153
+ shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
153
154
  };
154
155
  type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
155
156
  declare const timeline: (options: TimelineOptions) => TimelineToken;
@@ -185,4 +186,4 @@ type FamilyMetadata = {
185
186
  subKey: string;
186
187
  };
187
188
 
188
- export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, KeyedStateUpdate, LOG_LEVELS, Logger, MutableAtomFamily, MutableAtomFamilyOptions, MutableAtomOptions, MutableAtomToken, NO_OP, NotFoundError, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Silo, StateToken, StateUpdate, TimelineOptions, TimelineToken, TimelineUpdate, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdate, TransactionUpdateHandler, Transactors, UpdateHandler, Write, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };
189
+ export { type AtomEffect, type AtomFamily, type AtomFamilyOptions, type AtomOptions, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type Logger, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomOptions, type MutableAtomToken, NO_OP, NotFoundError, type Read, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type SelectorFamily, type SelectorFamilyOptions, type SelectorOptions, type SelectorToken, Silo, type StateToken, type StateUpdate, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateHandler, type Transactors, type UpdateHandler, type Write, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, type ƒn };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as Internal from 'atom.io/internal';
2
- import { Transceiver, Subject, Store, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
2
+ import { Transceiver, Subject, Store, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
3
3
  import { Json, JsonInterface } from 'atom.io/json';
4
4
 
5
5
  type Effectors<T> = {
@@ -150,6 +150,7 @@ type TimelineToken = {
150
150
  type TimelineOptions = {
151
151
  key: string;
152
152
  atoms: (AtomFamily<any, any> | AtomToken<any>)[];
153
+ shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
153
154
  };
154
155
  type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
155
156
  declare const timeline: (options: TimelineOptions) => TimelineToken;
@@ -185,4 +186,4 @@ type FamilyMetadata = {
185
186
  subKey: string;
186
187
  };
187
188
 
188
- export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, KeyedStateUpdate, LOG_LEVELS, Logger, MutableAtomFamily, MutableAtomFamilyOptions, MutableAtomOptions, MutableAtomToken, NO_OP, NotFoundError, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Silo, StateToken, StateUpdate, TimelineOptions, TimelineToken, TimelineUpdate, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdate, TransactionUpdateHandler, Transactors, UpdateHandler, Write, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };
189
+ export { type AtomEffect, type AtomFamily, type AtomFamilyOptions, type AtomOptions, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type Logger, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomOptions, type MutableAtomToken, NO_OP, NotFoundError, type Read, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type SelectorFamily, type SelectorFamilyOptions, type SelectorOptions, type SelectorToken, Silo, type StateToken, type StateUpdate, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateHandler, type Transactors, type UpdateHandler, type Write, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, type ƒn };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/atom.ts","../src/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["IMPLICIT","_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,OAAO;AAAA,EACjC;AACA,SAAO,WAAc,OAAO;AAC7B;AA+CO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,OAAO;AAAA,EACvC;AACA,SAAO,iBAAuB,OAAO;AACtC;;;ACjGA,YAAY,cAAc;AAGnB,IAAM,WAAW,CACvB,OACA,QAAiC,kBAAS,UACnC;AANR;AAOC,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,SAAgB,4BAAmB,OAAO,KAAK;AAChD;AAEO,IAAM,WAAW,CACvB,OACA,OACA,QAAiC,kBAAS,UAChC;AApBX;AAqBC,QAAM,YAAqB,uBAAc,OAAO,KAAK;AACrD,MAAI,WAAW;AACd;AAAA,EACD;AACA,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,EAAS,4BAAmB,OAAO,OAAO,KAAK;AAC/C,EAAS,wBAAe,KAAK;AAC9B;AAEA,IAAM,aAAa,CAAC,QAAgB,IAAI,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAC/D,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACjC,YACN,OACA,OACC;AACD;AAAA,MACC,GAAG,WAAW,MAAM,IAAI,CAAC,KAAK,MAAM,GAAG,yB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AAKQ,UAAS,OAAO,KAAK;AAChC,MAAI,OAAO,QAAW;AACrB,UAAM,IAAI;AAAA,MACT,iCAAiC,MAAM,GAAG,mCAAmC,MAAM,OAAO,IAAI;AAAA,IAC/F;AAAA,EACD;AACA,cAAM,OAAO,WAAb,mBAAqB,KAAK,oCAA6B,MAAM,GAAG;AAChE,QAAM,cAAc,GAAG,QAAQ,UAAU,KAAK,YAAY;AAC1D,SAAO,MAAM;AA/Fd,QAAAP;AAgGE,KAAAA,MAAA,MAAM,OAAO,WAAb,gBAAAA,IAAqB,KAAK,wCAAiC,MAAM,GAAG;AACpE,gBAAY;AAAA,EACb;AACD;;;AC9FA;AAAA,EACC,YAAAD;AAAA,EACA,kBAAAS;AAAA,EACA,sBAAAC;AAAA,EACA,kBAAAC;AAAA,OACM;AAmBA,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,oBAAmB,OAAO;AAClC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAD,gBAAe,OAAOT,UAAS,KAAK;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAW,gBAAe,OAAOX,UAAS,KAAK;AACrC;;;ACtCA,SAAS,YAAAA,WAAU,yBAAAY,wBAAuB,YAAAJ,iBAAgB;AAyCnD,SAAS,YACf,SACsB;AACtB,SAAOI,uBAAsB,OAAO;AACrC;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeZ,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKQ,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options)\n\t}\n\treturn createAtom<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<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 NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: 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 NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tfor (const logLevel of LOG_LEVELS) {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`👀 adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`🙈 unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`🙈 unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport const subscribeToTransaction = <ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Write<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
1
+ {"version":3,"sources":["../src/atom.ts","../src/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["IMPLICIT","_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,OAAO;AAAA,EACjC;AACA,SAAO,WAAc,OAAO;AAC7B;AA+CO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,OAAO;AAAA,EACvC;AACA,SAAO,iBAAuB,OAAO;AACtC;;;ACjGA,YAAY,cAAc;AAGnB,IAAM,WAAW,CACvB,OACA,QAAiC,kBAAS,UACnC;AANR;AAOC,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,SAAgB,4BAAmB,OAAO,KAAK;AAChD;AAEO,IAAM,WAAW,CACvB,OACA,OACA,QAAiC,kBAAS,UAChC;AApBX;AAqBC,QAAM,YAAqB,uBAAc,OAAO,KAAK;AACrD,MAAI,WAAW;AACd;AAAA,EACD;AACA,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,M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iBACZ,CAAe,OAA4B,QAAeZ,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKQ,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options)\n\t}\n\treturn createAtom<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<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 NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: 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 NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tfor (const logLevel of LOG_LEVELS) {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`👀 adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`🙈 unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`🙈 unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport const subscribeToTransaction = <ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Write<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/atom.ts","../src/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["IMPLICIT","_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,OAAO;AAAA,EACjC;AACA,SAAO,WAAc,OAAO;AAC7B;AA+CO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,OAAO;AAAA,EACvC;AACA,SAAO,iBAAuB,O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;;AC9FA;AAAA,EACC,YAAAD;AAAA,EACA,kBAAAS;AAAA,EACA,sBAAAC;AAAA,EACA,kBAAAC;AAAA,OACM;AAmBA,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,oBAAmB,OAAO;AAClC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAD,gBAAe,OAAOT,UAAS,KAAK;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAW,gBAAe,OAAOX,UAAS,KAAK;AACrC;;;ACtCA,SAAS,YAAAA,WAAU,yBAAAY,wBAAuB,YAAAJ,iBAAgB;AAyCnD,SAAS,YACf,SACsB;AACtB,SAAOI,uBAAsB,OAAO;AACrC;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeZ,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKQ,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options)\n\t}\n\treturn createAtom<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<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 NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: 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 NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tfor (const logLevel of LOG_LEVELS) {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`👀 adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`🙈 unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`🙈 unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport const subscribeToTransaction = <ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Write<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
1
+ {"version":3,"sources":["../src/atom.ts","../src/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["IMPLICIT","_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,OAAO;AAAA,EACjC;AACA,SAAO,WAAc,OAAO;AAC7B;AA+CO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,OAAO;AAAA,EACvC;AACA,SAAO,iBAAuB,OAAO;AACtC;;;ACjGA,YAAY,cAAc;AAGnB,IAAM,WAAW,CACvB,OACA,QAAiC,kBAAS,UACnC;AANR;AAOC,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,SAAgB,4BAAmB,OAAO,KAAK;AAChD;AAEO,IAAM,WAAW,CACvB,OACA,OACA,QAAiC,kBAAS,UAChC;AApBX;AAqBC,QAAM,YAAqB,uBAAc,OAAO,KAAK;AACrD,MAAI,WAAW;AACd;AAAA,EACD;AACA,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,EAAS,4BAAmB,OAAO,OAAO,KAAK;AAC/C,EAAS,wBAAe,KAAK;AAC9B;AAEA,IAAM,aAAa,CAAC,QAAgB,IAAI,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAC/D,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACjC,YACN,OACA,OACC;AACD;AAAA,MACC,GAAG,WAAW,MAAM,IAAI,CAAC,KAAK,MAAM,GAAG,yBACtC,MAAM,OAAO,IAC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KAAK;AAChC,MAAI,OAAO,QAAW;AACrB,UAAM,IAAI;AAAA,MACT,iCAAiC,MAAM,GAAG,mCAAmC,MAAM,OAAO,IAAI;AAAA,IAC/F;AAAA,EACD;AACA,cAAM,OAAO,WAAb,mBAAqB,KAAK,oCAA6B,MAAM,GAAG;AAChE,QAAM,cAAc,GAAG,QAAQ,UAAU,KAAK,YAAY;AAC1D,SAAO,MAAM;AA/Fd,QAAAP;AAgGE,KAAAA,MAAA,MAAM,OAAO,WAAb,gBAAAA,IAAqB,KAAK,wCAAiC,MAAM,GAAG;AACpE,gBAAY;AAAA,EACb;AACD;;;AC7FA;AAAA,EACC,YAAAD;AAAA,EACA,kBAAAS;AAAA,EACA,sBAAAC;AAAA,EACA,kBAAAC;AAAA,OACM;AAoBA,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,oBAAmB,OAAO;AAClC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAD,gBAAe,OAAOT,UAAS,KAAK;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAW,gBAAe,OAAOX,UAAS,KAAK;AACrC;;;ACxCA,SAAS,YAAAA,WAAU,yBAAAY,wBAAuB,YAAAJ,iBAAgB;AAyCnD,SAAS,YACf,SACsB;AACtB,SAAOI,uBAAsB,OAAO;AACrC;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeZ,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKQ,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options)\n\t}\n\treturn createAtom<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<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 NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: 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 NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tfor (const logLevel of LOG_LEVELS) {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`👀 adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`🙈 unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`🙈 unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport const subscribeToTransaction = <ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Write<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
@@ -179,13 +179,13 @@ declare class Tracker<Mutable extends Transceiver<any>> {
179
179
  private observeCore;
180
180
  private updateCore;
181
181
  mutableState: MutableAtomToken<Mutable, Json.Serializable>;
182
- latestUpdateState: AtomToken<typeof this$1.Update | null>;
182
+ latestUpdateState: AtomToken<typeof this.Update | null>;
183
183
  constructor(mutableState: MutableAtomToken<Mutable, Json.Serializable>, store?: Store);
184
184
  }
185
185
 
186
186
  declare class FamilyTracker<Core extends Transceiver<any>, FamilyMemberKey extends Json.Serializable> {
187
187
  private readonly Update;
188
- readonly findLatestUpdateState: AtomFamily<typeof this$1.Update | null, FamilyMemberKey>;
188
+ readonly findLatestUpdateState: AtomFamily<typeof this.Update | null, FamilyMemberKey>;
189
189
  readonly findMutableState: AtomFamily<Core, FamilyMemberKey>;
190
190
  constructor(findMutableState: AtomFamily<Core, FamilyMemberKey>, store?: Store);
191
191
  }
@@ -230,6 +230,7 @@ type Timeline = {
230
230
  type: `timeline`;
231
231
  key: string;
232
232
  at: number;
233
+ shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
233
234
  timeTraveling: `into_future` | `into_past` | null;
234
235
  history: TimelineUpdate[];
235
236
  selectorTime: number | null;
@@ -356,4 +357,4 @@ declare const setState__INTERNAL: <T>(state: Atom<T> | Selector<T>, value: T | (
356
357
 
357
358
  declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
358
359
 
359
- export { Atom, FamilyTracker, Fated, Future, IMPLICIT, Loadable, Modify, MutableAtom, OperationProgress, ReadonlySelector, Selector, Signal, Store, StoreCore, Subject, TRANSACTION_PHASES, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate, Tracker, Transaction, TransactionIdle, TransactionPhase, TransactionStatus, TransactionUpdateInProgress, Transceiver, TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomMutable, isAtomTokenMutable, isDone, isSelectorDefault, isTransceiver, isValueCached, lookup, lookupSelectorSources, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, redoTransactionUpdate, redo__INTERNAL, registerSelector, setState__INTERNAL, subscribeToRootAtoms, target, timeline__INTERNAL, traceAllSelectorAtoms, traceSelectorAtoms, transaction__INTERNAL, undoTransactionUpdate, undo__INTERNAL, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
360
+ export { type Atom, FamilyTracker, type Fated, Future, IMPLICIT, type Loadable, type Modify, type MutableAtom, type OperationProgress, type ReadonlySelector, type Selector, type Signal, Store, type StoreCore, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionIdle, type TransactionPhase, type TransactionStatus, type TransactionUpdateInProgress, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomMutable, isAtomTokenMutable, isDone, isSelectorDefault, isTransceiver, isValueCached, lookup, lookupSelectorSources, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, redoTransactionUpdate, redo__INTERNAL, registerSelector, setState__INTERNAL, subscribeToRootAtoms, target, timeline__INTERNAL, traceAllSelectorAtoms, traceSelectorAtoms, transaction__INTERNAL, undoTransactionUpdate, undo__INTERNAL, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
@@ -179,13 +179,13 @@ declare class Tracker<Mutable extends Transceiver<any>> {
179
179
  private observeCore;
180
180
  private updateCore;
181
181
  mutableState: MutableAtomToken<Mutable, Json.Serializable>;
182
- latestUpdateState: AtomToken<typeof this$1.Update | null>;
182
+ latestUpdateState: AtomToken<typeof this.Update | null>;
183
183
  constructor(mutableState: MutableAtomToken<Mutable, Json.Serializable>, store?: Store);
184
184
  }
185
185
 
186
186
  declare class FamilyTracker<Core extends Transceiver<any>, FamilyMemberKey extends Json.Serializable> {
187
187
  private readonly Update;
188
- readonly findLatestUpdateState: AtomFamily<typeof this$1.Update | null, FamilyMemberKey>;
188
+ readonly findLatestUpdateState: AtomFamily<typeof this.Update | null, FamilyMemberKey>;
189
189
  readonly findMutableState: AtomFamily<Core, FamilyMemberKey>;
190
190
  constructor(findMutableState: AtomFamily<Core, FamilyMemberKey>, store?: Store);
191
191
  }
@@ -230,6 +230,7 @@ type Timeline = {
230
230
  type: `timeline`;
231
231
  key: string;
232
232
  at: number;
233
+ shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
233
234
  timeTraveling: `into_future` | `into_past` | null;
234
235
  history: TimelineUpdate[];
235
236
  selectorTime: number | null;
@@ -356,4 +357,4 @@ declare const setState__INTERNAL: <T>(state: Atom<T> | Selector<T>, value: T | (
356
357
 
357
358
  declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
358
359
 
359
- export { Atom, FamilyTracker, Fated, Future, IMPLICIT, Loadable, Modify, MutableAtom, OperationProgress, ReadonlySelector, Selector, Signal, Store, StoreCore, Subject, TRANSACTION_PHASES, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate, Tracker, Transaction, TransactionIdle, TransactionPhase, TransactionStatus, TransactionUpdateInProgress, Transceiver, TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomMutable, isAtomTokenMutable, isDone, isSelectorDefault, isTransceiver, isValueCached, lookup, lookupSelectorSources, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, redoTransactionUpdate, redo__INTERNAL, registerSelector, setState__INTERNAL, subscribeToRootAtoms, target, timeline__INTERNAL, traceAllSelectorAtoms, traceSelectorAtoms, transaction__INTERNAL, undoTransactionUpdate, undo__INTERNAL, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
360
+ export { type Atom, FamilyTracker, type Fated, Future, IMPLICIT, type Loadable, type Modify, type MutableAtom, type OperationProgress, type ReadonlySelector, type Selector, type Signal, Store, type StoreCore, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionIdle, type TransactionPhase, type TransactionStatus, type TransactionUpdateInProgress, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomMutable, isAtomTokenMutable, isDone, isSelectorDefault, isTransceiver, isValueCached, lookup, lookupSelectorSources, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, redoTransactionUpdate, redo__INTERNAL, registerSelector, setState__INTERNAL, subscribeToRootAtoms, target, timeline__INTERNAL, traceAllSelectorAtoms, traceSelectorAtoms, transaction__INTERNAL, undoTransactionUpdate, undo__INTERNAL, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
@@ -553,7 +553,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
553
553
  );
554
554
  }
555
555
  atom.subject.subscribe(`timeline`, (update) => {
556
- var _a, _b, _c, _d, _e;
556
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
557
557
  const currentSelectorKey = store.operation.open && store.operation.token.type === `selector` ? store.operation.token.key : null;
558
558
  const currentSelectorTime = store.operation.open && store.operation.token.type === `selector` ? store.operation.time : null;
559
559
  const currentTransactionKey = store.transactionStatus.phase === `applying` ? store.transactionStatus.key : null;
@@ -594,7 +594,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
594
594
  const unsubscribe = currentTransaction.subject.subscribe(
595
595
  `timeline:${tl.key}`,
596
596
  (update2) => {
597
- var _a2;
597
+ var _a2, _b2, _c2;
598
598
  unsubscribe();
599
599
  if (tl.timeTraveling === null && currentTransactionTime) {
600
600
  if (tl.at !== tl.history.length) {
@@ -618,12 +618,15 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
618
618
  }, update2), {
619
619
  atomUpdates
620
620
  });
621
- tl.history.push(timelineTransactionUpdate);
622
- tl.at = tl.history.length;
623
- tl.subject.next(timelineTransactionUpdate);
621
+ const willCapture = (_b2 = (_a2 = tl.shouldCapture) == null ? void 0 : _a2.call(tl, timelineTransactionUpdate, tl)) != null ? _b2 : true;
622
+ if (willCapture) {
623
+ tl.history.push(timelineTransactionUpdate);
624
+ tl.at = tl.history.length;
625
+ tl.subject.next(timelineTransactionUpdate);
626
+ }
624
627
  }
625
628
  tl.transactionKey = null;
626
- (_a2 = store.config.logger) == null ? void 0 : _a2.info(
629
+ (_c2 = store.config.logger) == null ? void 0 : _c2.info(
627
630
  `\u231B timeline "${tl.key}" got a transaction_update "${update2.key}"`
628
631
  );
629
632
  }
@@ -664,8 +667,15 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
664
667
  );
665
668
  }
666
669
  }
667
- if (latestUpdate)
668
- tl.subject.next(latestUpdate);
670
+ if (latestUpdate) {
671
+ const willCaptureSelectorUpdate = (_f = (_e = tl.shouldCapture) == null ? void 0 : _e.call(tl, latestUpdate, tl)) != null ? _f : true;
672
+ if (willCaptureSelectorUpdate) {
673
+ tl.subject.next(latestUpdate);
674
+ } else {
675
+ tl.history.pop();
676
+ tl.at = tl.history.length;
677
+ }
678
+ }
669
679
  } else {
670
680
  const timestamp = Date.now();
671
681
  tl.selectorTime = null;
@@ -682,12 +692,15 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
682
692
  if (atom.family) {
683
693
  atomUpdate.family = atom.family;
684
694
  }
685
- tl.history.push(atomUpdate);
686
- tl.subject.next(atomUpdate);
687
- (_e = store.config.logger) == null ? void 0 : _e.info(
695
+ const willCapture = (_h = (_g = tl.shouldCapture) == null ? void 0 : _g.call(tl, atomUpdate, tl)) != null ? _h : true;
696
+ (_i = store.config.logger) == null ? void 0 : _i.info(
688
697
  `\u231B timeline "${tl.key}" got an atom_update to "${atom.key}"`
689
698
  );
690
- tl.at = tl.history.length;
699
+ if (willCapture) {
700
+ tl.history.push(atomUpdate);
701
+ tl.at = tl.history.length;
702
+ tl.subject.next(atomUpdate);
703
+ }
691
704
  }
692
705
  }
693
706
  });
@@ -788,6 +801,9 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
788
801
  install: (store2) => timeline__INTERNAL(options, store2, tl),
789
802
  subject: new Subject()
790
803
  });
804
+ if (options.shouldCapture) {
805
+ tl.shouldCapture = options.shouldCapture;
806
+ }
791
807
  const core = target(store);
792
808
  for (const tokenOrFamily of options.atoms) {
793
809
  const timelineKey = core.timelineAtoms.getRelatedKey(tokenOrFamily.key);
@@ -800,9 +816,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
800
816
  if (tokenOrFamily.type === `atom_family`) {
801
817
  const family = tokenOrFamily;
802
818
  family.subject.subscribe(`timeline:${options.key}`, (token2) => {
803
- if (!core.atoms.has(token2.key)) {
804
- addAtomToTimeline(token2, tl, store);
805
- }
819
+ addAtomToTimeline(token2, tl, store);
806
820
  });
807
821
  for (const atom of core.atoms.values()) {
808
822
  if (((_c = atom.family) == null ? void 0 : _c.key) === family.key) {
@@ -1368,6 +1382,7 @@ var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
1368
1382
 
1369
1383
  // src/selector/trace-selector-atoms.ts
1370
1384
  var traceSelectorAtoms = (selectorKey, dependency, store) => {
1385
+ var _a;
1371
1386
  const roots = [];
1372
1387
  const sources = lookupSelectorSources(dependency.key, store);
1373
1388
  let depth = 0;
@@ -1375,6 +1390,11 @@ var traceSelectorAtoms = (selectorKey, dependency, store) => {
1375
1390
  const source = sources.shift();
1376
1391
  ++depth;
1377
1392
  if (depth > 999) {
1393
+ (_a = store.config.logger) == null ? void 0 : _a.warn(
1394
+ `Maximum selector dependency depth exceeded 999 in selector "${selectorKey}".`
1395
+ );
1396
+ }
1397
+ if (depth > 99999) {
1378
1398
  throw new Error(
1379
1399
  `Maximum selector dependency depth exceeded in selector "${selectorKey}".`
1380
1400
  );