import { AsJSON, ConstructorOf, Ctor, EnvironmentData, Fn, RootStore, Store, Transceiver } from "atom.io/internal"; import { stringified } from "atom.io/foundations/json"; import { UList } from "atom.io/transceivers/u-list"; import { Loadable as Loadable$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, ReadonlyPureSelectorToken as ReadonlyPureSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, RegularAtomToken as RegularAtomToken$1, ViewOf as ViewOf$1, WritableFamilyToken as WritableFamilyToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, WritableToken as WritableToken$1, findState as findState$1 } from "atom.io"; import { Junction, JunctionEntriesBase, JunctionSchemaBase, Refinement as Refinement$1 } from "atom.io/foundations/junction"; import { Canonical } from "atom.io/foundations/canonical"; import { DeepReadonly, Flat, ViewOf } from "atom.io/foundations/type-utils"; //#region src/main/timeline.d.ts type TimelineManageable = AtomFamilyToken | AtomToken; type AtomOnly = M extends AtomFamilyToken ? AtomToken : M extends AtomToken ? M : never; type TimelineInspection = { at: number; length: number; }; /** A deeply readonly logical update that is about to settle in a timeline. */ type TimelineRecordEvent = { readonly type: `timeline_record`; readonly event: DeepReadonly>; }; /** Safe history-collection tools supplied to a {@link TimelineEffect}. */ type TimelineEffectors = { /** Observe complete logical updates before they settle in the timeline. */ onRecord: (callback: (event: TimelineRecordEvent) => void) => void; /** Retain at most this many complete undo steps. */ cullUndoSteps: (limit: number) => void; /** The token of the timeline. */ token: TimelineToken; /** The store in which the timeline exists. */ store: Store; }; /** A lifecycle hook that observes and safely collects timeline history. */ type TimelineEffect = (tools: TimelineEffectors) => void | (() => void); /** * Describes how one atom family is divided among the members of a timeline family. * * Returning `undefined` from `timelineKey` excludes that atom-family member from * every timeline. */ type TimelineFamilyScope = AtomFamilyToken> = { /** The atom family whose members will be routed. */ family: ManagedFamily; /** Selects the timeline key for an atom-family member. */ timelineKey: (key: MemberKey) => TimelineKey | undefined; }; /** Options for creating a family of keyed timelines. */ type TimelineFamilyOptions = TimelineFamilyScope> = { /** The unique identifier of the timeline family. */ key: string; /** Atom families partitioned among the timeline-family members. */ scope: readonly Scope[]; /** Creates lifecycle hooks for each timeline-family member. */ effects?: (key: TimelineKey) => readonly TimelineEffect[]; }; /** * Route an atom family's members into a timeline family. * * The `timelineKey` function receives each atom-family member's key. It returns * the key of the timeline that should record that member, or `undefined` to leave * the member untracked. * * An atom family can belong to only one timeline or timeline family. * * @param family - The atom family to route. * @param options - The function that selects a timeline key for each member. * @returns A scope descriptor for {@link timelineFamily}. */ declare function scopeFamily(family: AtomFamilyToken, options: { timelineKey: (key: MemberKey) => TimelineKey | undefined; }): TimelineFamilyScope>; /** * Inspect a timeline's current history position. * @param timelineToken - A {@link TimelineToken} * @overload Timeline */ declare function inspectTimeline(timelineToken: TimelineToken): TimelineInspection; /** * Inspect a member of a timeline family, creating it if needed. * @param family - A {@link TimelineFamilyToken}. * @param key - The key of the timeline-family member. * @overload Timeline Family Member */ declare function inspectTimeline(family: TimelineFamilyToken, key: NoInfer): TimelineInspection; /** * If there is an update ahead of the cursor (in the future of this {@link timelineToken}), apply it and move the cursor to the next update * @param timelineToken - A {@link TimelineToken} * @overload Timeline */ declare function redo(timelineToken: TimelineToken): void; /** * Replay the next update in a timeline-family member, creating it if needed. * @param family - A {@link TimelineFamilyToken}. * @param key - The key of the timeline-family member. * @overload Timeline Family Member */ declare function redo(family: TimelineFamilyToken, key: NoInfer): void; /** * Reverse the last update on the {@link timelineToken} and move the cursor to the previous update * @param timelineToken - A {@link TimelineToken} * @overload Timeline */ declare function undo(timelineToken: TimelineToken): void; /** * Reverse the last update in a timeline-family member, creating it if needed. * @param family - A {@link TimelineFamilyToken}. * @param key - The key of the timeline-family member. * @overload Timeline Family Member */ declare function undo(family: TimelineFamilyToken, key: NoInfer): void; /** * Remove all recorded history from the {@link timelineToken} and reset its cursor to the beginning * @param timelineToken - A {@link TimelineToken} * @overload Timeline */ declare function clearTimeline(timelineToken: TimelineToken): void; /** * Remove all history from a timeline-family member, creating it if needed. * @param family - A {@link TimelineFamilyToken}. * @param key - The key of the timeline-family member. * @overload Timeline Family Member */ declare function clearTimeline(family: TimelineFamilyToken, key: NoInfer): void; /** * Permanently dispose of a timeline and its recorded history. * @param timelineToken - The timeline to dispose of. * @overload Timeline */ declare function disposeTimeline(timelineToken: TimelineToken): void; /** * Permanently dispose of a timeline-family member and its recorded history. * * If the member does not exist, it will not be created. * * @param family - A {@link TimelineFamilyToken}. * @param key - The key of the timeline-family member. * @overload Timeline Family Member */ declare function disposeTimeline(family: TimelineFamilyToken, key: NoInfer): void; type TimelineOptions = { /** The unique identifier of the timeline */ key: string; /** The managed atoms (and families of atoms) to record */ scope: ManagedAtom[]; /** Hooks that observe and safely collect timeline history. */ effects?: readonly TimelineEffect[]; }; /** * Create a timeline, a mechanism for recording, undoing, and replaying changes to groups of atoms * @param options - {@link TimelineOptions} * @returns A reference to the timeline created: a {@link TimelineToken} */ declare function timeline(options: TimelineOptions): TimelineToken; /** * Create a family of independent timelines, keyed and scoped by atom families. * * Timeline-family members are created only when they are first used. Existing and * future atom-family members are routed to them by the descriptors from * {@link scopeFamily}. * * @param options - {@link TimelineFamilyOptions} * @returns A reference to the timeline family created: a {@link TimelineFamilyToken} */ declare function timelineFamily = TimelineFamilyScope>(options: TimelineFamilyOptions): TimelineFamilyToken; /** * Find a member of a timeline family, creating it if needed. * * Repeated calls with the same family and key return the same serializable token. * * @param family - A {@link TimelineFamilyToken}. * @param key - The key of the timeline-family member. * @returns A reference to the timeline-family member: a {@link TimelineToken} */ declare function findTimeline(family: TimelineFamilyToken, key: NoInfer): TimelineToken; //#endregion //#region src/main/tokens.d.ts /** * A token is an object that uniquely identifies a particular state, family, timeline, or transaction. * * While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank. * * Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}. * * Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}. * * Tokens are fully serializable, so they can be passed between processes. */ type AtomIOToken = ReadableFamilyToken | ReadableToken | TimelineFamilyToken | TimelineToken | TransactionToken; type ReadableToken = AtomToken | SelectorToken; type WritableToken = AtomToken | WritableSelectorToken; /** * States belonging to this family can be read from the store. */ type ReadableFamilyToken = AtomFamilyToken | SelectorFamilyToken; /** * States belonging to this family can be written directly. */ type WritableFamilyToken = AtomFamilyToken | WritableSelectorFamilyToken; type TimelineToken = { /** The unique identifier of the timeline */ key: string; /** Discriminator */ type: `timeline`; /** Present if the timeline belongs to a family. */ family?: FamilyMetadata; /** Never present. This is a marker that preserves the type of the managed atoms */ __M?: M; }; /** * A serializable reference to a family of keyed timelines. * * Use {@link findTimeline} to get a timeline-family member. */ type TimelineFamilyToken = { /** The unique identifier of the timeline family */ key: string; /** Discriminator */ type: `timeline_family`; /** Never present. This is a marker that preserves the type of keys used for timelines in this family */ __K?: K; /** Never present. This is a marker that preserves the type of the managed atoms */ __M?: M; }; type TransactionToken = { /** The unique identifier of the transaction */ key: string; /** Discriminator */ type: `transaction`; /** Never present. This is a marker that preserves the type of the transaction function */ __F?: F; }; type TokenType | ReadableToken | TransactionToken> = Comparison extends ReadableToken ? RepresentedValue | RepresentedError : Comparison extends ReadableFamilyToken ? RepresentedValue | RepresentedError : Comparison extends TransactionToken ? TokenFn : never; type AtomToken = MutableAtomToken ? T : never, K> | RegularAtomToken; type RegularAtomToken = { /** The unique identifier of the atom. */ key: string; /** Discriminator. */ type: `atom`; /** Present if the atom belongs to a family. */ family?: FamilyMetadata; /** Never present. This is a marker that preserves the type of the atom's value. */ __T?: T; /** Never present. This is a marker that preserves the type of errors this atom is capable of catching and setting as its value. */ __E?: E; }; type MutableAtomToken, K extends Canonical = any> = { /** The unique identifier of the atom. */ key: string; /** Discriminator. */ type: `mutable_atom`; /** Present if the atom belongs to a family. */ family?: FamilyMetadata; /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */ __J?: AsJSON; }; type SelectorToken = ReadonlySelectorToken | WritableSelectorToken; type ReadonlySelectorToken = ReadonlyHeldSelectorToken | ReadonlyPureSelectorToken; type WritableSelectorToken = WritableHeldSelectorToken | WritablePureSelectorToken; type PureSelectorToken = ReadonlyPureSelectorToken | WritablePureSelectorToken; type HeldSelectorToken = ReadonlyHeldSelectorToken | WritableHeldSelectorToken; type WritablePureSelectorToken = { /** The unique identifier of the selector. */ key: string; /** Discriminator. */ type: `writable_pure_selector`; /** Present if the selector belongs to a family. */ family?: FamilyMetadata; /** Never present. This is a marker that preserves the type of the selector's value. */ __T?: T; /** Never present. This is a marker that preserves the type of errors this selector is capable of catching and setting as its value. */ __E?: E; }; type WritableHeldSelectorToken = { /** The unique identifier of the selector. */ key: string; /** Discriminator. */ type: `writable_held_selector`; /** Present if the selector belongs to a family. */ family?: FamilyMetadata; /** Never present. This is a marker that preserves the type of the selector's value. */ __T?: T; }; type ReadonlyPureSelectorToken = { /** The unique identifier of the selector. */ key: string; /** Discriminator. */ type: `readonly_pure_selector`; /** Present if the selector belongs to a family. */ family?: FamilyMetadata; /** Never present. This is a marker that preserves the type of the selector's value. */ __T?: T; /** Never present. This is a marker that preserves the type of errors this selector is capable of catching and setting as its value. */ __E?: E; }; type ReadonlyHeldSelectorToken = { /** The unique identifier of the selector. */ key: string; /** Discriminator. */ type: `readonly_held_selector`; /** Present if the selector belongs to a family. */ family?: FamilyMetadata; /** Never present. This is a marker that preserves the type of the selector's value. */ __T?: T; }; /** * Identifies a state's connection to its family. */ type FamilyMetadata = { /** The family's unique key. */ key: string; /** The family member's unique identifier, in the form of a string. */ subKey: stringified; }; type AtomFamilyToken = MutableAtomFamilyToken ? T : never, K> | RegularAtomFamilyToken; type RegularAtomFamilyToken = { /** The unique identifier of the atom family */ key: string; /** Discriminator */ type: `atom_family`; /** Never present. This is a marker that preserves the type of atoms in this family */ __T?: T; /** Never present. This is a marker that preserves the type of keys used for atoms in this family */ __K?: K; /** Never present. This is a marker that preserves the type of errors this family is capable of catching and setting as its value. */ __E?: E; }; type MutableAtomFamilyToken, K extends Canonical> = { /** The unique identifier of the atom family */ key: string; /** Discriminator */ type: `mutable_atom_family`; /** Never present. This is a marker that preserves the type of atoms in this family */ __T?: T; /** Never present. This is a marker that preserves the type of keys used for atoms in this family */ __K?: K; }; type SelectorFamilyToken = ReadonlySelectorFamilyToken | WritableSelectorFamilyToken; type ReadonlySelectorFamilyToken = ReadonlyHeldSelectorFamilyToken | ReadonlyPureSelectorFamilyToken; type WritableSelectorFamilyToken = WritableHeldSelectorFamilyToken | WritablePureSelectorFamilyToken; type PureSelectorFamilyToken = ReadonlyPureSelectorFamilyToken | WritablePureSelectorFamilyToken; type HeldSelectorFamilyToken = ReadonlyHeldSelectorFamilyToken | WritableHeldSelectorFamilyToken; type WritablePureSelectorFamilyToken = { /** The unique identifier of the family */ key: string; /** Discriminator */ type: `writable_pure_selector_family`; /** Never present. This is a marker that preserves the type of the value of each family member */ __T?: T; /** Never present. This is a marker that preserves the type of keys used for each family member */ __K?: K; /** Never present. This is a marker that preserves the type of errors this family is capable of catching and setting as its value. */ __E?: E; }; type ReadonlyPureSelectorFamilyToken = { /** The unique identifier of the family */ key: string; /** Discriminator */ type: `readonly_pure_selector_family`; /** Never present. This is a marker that preserves the type of the value of each family member */ __T?: T; /** Never present. This is a marker that preserves the type of keys used for each family member */ __K?: K; /** Never present. This is a marker that preserves the type of errors this family is capable of catching and setting as its value. */ __E?: E; }; type WritableHeldSelectorFamilyToken = { /** The unique identifier of the family */ key: string; /** Discriminator */ type: `writable_held_selector_family`; /** Never present. This is a marker that preserves the type of the value of each family member */ __T?: T; /** Never present. This is a marker that preserves the type of keys used for each family member */ __K?: K; }; type ReadonlyHeldSelectorFamilyToken = { /** The unique identifier of the family */ key: string; /** Discriminator */ type: `readonly_held_selector_family`; /** Never present. This is a marker that preserves the type of the value of each family member */ __T?: T; /** Never present. This is a marker that preserves the type of keys used for each family member */ __K?: K; }; //#endregion //#region src/main/events.d.ts type StateUpdate = { readonly oldValue?: ViewOf$1; readonly newValue: ViewOf$1; }; type AtomUpdateEvent> = { type: `atom_update`; token: A; update: StateUpdate>; timestamp: number; }; type SelectorUpdateSubEvent> = AtomUpdateEvent | AtomCreationEvent; type TimelineSelectorUpdateEvent = { type: `selector_update`; token: SelectorToken; subEvents: SelectorUpdateSubEvent>[]; timestamp: number; }; type AtomCreationEvent> = { type: `atom_creation`; token: A; timestamp: number; value?: TokenType; }; type AtomDisposalEvent> = { type: `atom_disposal`; token: A; timestamp: number; value?: TokenType; }; type AtomLifecycleEvent> = AtomCreationEvent | AtomDisposalEvent; type MoleculeCreationEvent = { type: `molecule_creation`; key: Canonical; provenance: Canonical; timestamp: number; }; type MoleculeDisposalEvent = { type: `molecule_disposal`; key: Canonical; provenance: stringified[]; values: [key: string, value: any][]; timestamp: number; }; type MoleculeTransferEvent = { type: `molecule_transfer`; key: Canonical; exclusive: boolean; from: Canonical[]; to: Canonical[]; timestamp: number; }; type TransactionSubEvent = AtomLifecycleEvent> | AtomUpdateEvent> | MoleculeCreationEvent | MoleculeDisposalEvent | MoleculeTransferEvent | TransactionOutcomeEvent>; type TransactionOutcomeEvent> = { type: `transaction_outcome`; token: T; id: string; timestamp: number; subEvents: TransactionSubEvent[]; params: Parameters>; output: ReturnType>; }; type TimelineEvent = { checkpoint?: true; } & (AtomUpdateEvent> | AtomCreationEvent> | AtomDisposalEvent> | TimelineSelectorUpdateEvent | TransactionOutcomeEvent>); type TimelineCullEvent = { type: `timeline_cull`; target: `undo_steps`; /** Logical undo steps available before collection. */ from: number; /** Logical undo steps remaining after collection. */ to: number; }; type TimelineUpdate = { type: `timeline_update`; event: TimelineEvent | TimelineCullEvent | `clear` | `redo` | `undo`; at: number; length: number; }; //#endregion //#region src/main/atom.d.ts type RegularAtomOptions = { /** The unique identifier of the atom */ key: string; /** The starting value of the atom */ default: T | (() => T); /** Hooks used to run side effects when the atom is set */ effects?: readonly AtomEffect[]; /** The classes of errors that might be thrown when deriving the atom's default value */ catch?: readonly Ctor[]; }; /** * Create a regular atom, a global reactive variable in the implicit store * @param options - {@link RegularAtomOptions}. * @returns * A reference to the atom created: a {@link RegularAtomToken} */ declare function atom(options: RegularAtomOptions): RegularAtomToken; type MutableAtomOptions> = { /** The unique identifier of the atom */ key: string; /** A constructor for the atom's value */ class: ConstructorOf; /** Hooks used to run side effects when the atom is set */ effects?: readonly AtomEffect[]; }; /** * Create a mutable atom, a global reactive variable in the implicit store * * The value of a mutable atom must be some kind of {@link Transceiver}. * * @param options - {@link MutableAtomOptions}. * @returns * A reference to the atom created: a {@link MutableAtomToken} */ declare function mutableAtom>(options: MutableAtomOptions): MutableAtomToken; /** * A function that runs side effects when the atom is set * @param tools - {@link Effectors} that can be used to run side effects * @returns * Optionally, a cleanup function that will be called when the atom is disposed */ type AtomEffect = (tools: Effectors) => Loadable$1<(() => void) | void>; type Effectors = { /** * Reset the value of the atom to its default */ resetSelf: () => void; /** * Set the value of the atom * @param next - The new value of the atom, or a setter function */ setSelf: (next: New | ((old: T) => New)) => void; /** Subscribe to changes to the atom */ onSet: (callback: (options: StateUpdate) => void) => void; /** The token of the atom */ token: T extends Transceiver ? MutableAtomToken : AtomToken; /** The store in which the atom exists */ store: Store; }; type RegularAtomFamilyOptions = { /** The unique identifier of the atom family */ key: string; /** The starting value of the atom family */ default: T | ((key: K) => T); /** Hooks used to run side effects when an atom in the family is set */ effects?: (key: K) => AtomEffect[]; /** The classes of errors that might be thrown when deriving the atom's default value */ catch?: readonly Ctor[]; }; /** * Create a family of regular atoms, allowing for the dynamic creation and disposal of atoms. * @param options - {@link RegularAtomFamilyOptions} * @returns * A reference to the atom family created: a {@link RegularAtomFamilyToken} */ declare function atomFamily(options: RegularAtomFamilyOptions): RegularAtomFamilyToken; type MutableAtomFamilyOptions, K extends Canonical> = { /** The unique identifier of the atom family */ key: string; /** The class of the transceiver to be created */ class: ConstructorOf; /** Hooks used to run side effects when an atom in the family is set */ effects?: (key: K) => AtomEffect[]; }; /** * Create a family of mutable atoms, allowing for the dynamic creation and disposal of atoms. * * The value of a mutable atom must be some kind of {@link Transceiver}. * * @param options - {@link MutableAtomFamilyOptions} * @returns * A reference to the atom family created: a {@link MutableAtomFamilyToken} */ declare function mutableAtomFamily, K extends Canonical>(options: MutableAtomFamilyOptions): MutableAtomFamilyToken; //#endregion //#region src/main/dispose-state.d.ts /** * Disposes of a state in the implicit store. * * Only family members can be disposed of. * * @param token - The token of the state to dispose * @overload Default */ declare function disposeState(token: ReadableToken): void; /** * Disposes of a state in the implicit store. * * Only family members can be disposed of. * * @param token - The token of the state family to dispose * @param key - The unique key of the state to dispose * @overload Streamlined */ declare function disposeState(token: ReadableFamilyToken, key: K): void; //#endregion //#region src/main/find-state.d.ts /** * Finds a {@link MutableAtomToken} in the store, without accessing its value. * * In an ephemeral store, this will create a new atom if one does not exist with the given key. * * In an immortal store, a "counterfeit" atom token will be returned in this case and a warning will be logged. * * @param token - A {@link MutableAtomFamilyToken} * @param key - The key of the state * @returns * The current value of the state * @overload Mutable Atom */ declare function findState, K extends Canonical, Key extends K>(token: MutableAtomFamilyToken, key: Key): MutableAtomToken$1; /** * Finds a {@link RegularAtomToken} in the store, without accessing its value. * * In an ephemeral store, this will create a new atom if one does not exist with the given key. * * In an immortal store, a "counterfeit" atom token will be returned in this case and a warning will be logged. * * @param token - The token of the state family * @param key - The key of the state * @returns * The current value of the state * @overload Regular Atom */ declare function findState(token: RegularAtomFamilyToken, key: Key): RegularAtomToken$1; /** * Finds a {@link WritableSelectorToken} in the store, without accessing its value. * * In an ephemeral store, this will create a new selector if one does not exist with the given key. * * In an immortal store, a "counterfeit" selector token will be returned in this case and a warning will be logged. * * @param token - The token of the state family * @param key - The key of the state * @returns * The current value of the state * @overload Writable Selector */ declare function findState(token: WritableSelectorFamilyToken$1, key: Key): WritableSelectorToken$1; /** * Finds a {@link ReadonlySelectorToken} in the store, without accessing its value. * * In an ephemeral store, this will create a new selector if one does not exist with the given key. * * In an immortal store, a "counterfeit" selector token will be returned in this case and a warning will be logged. * * @param token - The token of the state family * @param key - The key of the state * @returns * The current value of the state * @overload Readonly Selector */ declare function findState(token: ReadonlySelectorFamilyToken$1, key: Key): ReadonlySelectorToken$1; /** * Finds a {@link WritableToken} in the store, without accessing its value. * * In an ephemeral store, this will create a new atom or selector if one does not exist with the given key. * * In an immortal store, a "counterfeit" token will be returned in this case and a warning will be logged. * * @param token - The token of the state family * @param key - The key of the state * @returns * The current value of the state * @overload Writable State */ declare function findState(token: WritableFamilyToken$1, key: Key): WritableToken$1; /** * Finds a {@link MutableAtomToken} in the store, without accessing its value. * * In an ephemeral store, this will create a new atom or selector if one does not exist with the given key. * * In an immortal store, a "counterfeit" token will be returned in this case and a warning will be logged. * * @param token - A {@link ReadableFamilyToken} * @param key - The key of the state * @returns * The current value of the state * @overload Unknown * @default */ declare function findState(token: ReadableFamilyToken$1, key: Key): ReadableToken$1; //#endregion //#region src/main/get-json-token.d.ts /** * Get the JSON form of a mutable atom as a writable state token. * @param token - A {@link MutableAtomToken} * @returns A token representing the mutable atom's JSON form * @overload Mutable Atom */ declare function getJsonToken, K extends Canonical>(token: MutableAtomToken): WritablePureSelectorToken, K>; /** * Get the JSON form of a mutable atom family member as a writable state token. * @param token - A {@link MutableAtomFamilyToken} * @param key - The key of the family member * @returns A token representing the mutable atom family member's JSON form * @overload Mutable Atom Family */ declare function getJsonToken, K extends Canonical, Key extends K>(token: MutableAtomFamilyToken, key: NoInfer): WritablePureSelectorToken, Key>; //#endregion //#region src/main/get-state.d.ts /** * Read or compute the current value of a state * @param token - The token of the state to get * @return The current value of the state * @overload Default * @default */ declare function getState(token: ReadableToken): ViewOf$1; /** * Read or compute the current value of a state * @param token - The token of a state family * @param key - The unique key of the state to get * @return The current value of the state * @overload Streamlined */ declare function getState(token: ReadableFamilyToken, key: NoInfer): ViewOf$1; //#endregion //#region src/main/join.d.ts type JoinOptions = Flat & { /** Unique identifier of the join */ readonly key: string; /** How many relations are allowed in each direction? */ readonly cardinality: Cardinality; /** Type guard for the type of the left side */ readonly isAType: Refinement$1; /** Type guard for the type of the right side */ readonly isBType: Refinement$1; }> & Partial>; type JoinToken = { /** Unique identifier of the join */ key: string; /** Discriminator */ type: `join`; /** How many relations are allowed in each direction? */ cardinality: Cardinality; /** Name of the join's left side */ a: AName; /** Name of the join's right side */ b: BName; /** Never present. This is a marker that preserves the type of the left side's keys */ __aType?: A; /** Never present. This is a marker that preserves the type of the right side's keys */ __bType?: B; }; /** * Create a join, an interface for managing relations between two sets of keys. * * Use joins when it is important to view relationships from either side. * * Under the hood, joins coordinate changes of multiple atoms to support that the desired relationships stay consistent. * * @param options - {@link JoinOptions} * @returns * A reference to the join created: a {@link JoinToken} */ declare function join(options: JoinOptions): JoinToken; type JoinStates = Cardinality extends `1:1` ? { readonly [N in AName as `${N}KeyOf${Capitalize}`]: ReadonlyPureSelectorToken$1; } & { readonly [N in BName as `${N}KeyOf${Capitalize}`]: ReadonlyPureSelectorToken$1; } : Cardinality extends `1:n` ? { readonly [N in AName as `${N}KeyOf${Capitalize}`]: ReadonlyPureSelectorToken$1; } & { readonly [N in BName as `${N}KeysOf${Capitalize}`]: ReadonlyPureSelectorToken$1; } : Cardinality extends `n:n` ? { readonly [N in AName as `${N}KeysOf${Capitalize}`]: ReadonlyPureSelectorToken$1; } & { readonly [N in BName as `${N}KeysOf${Capitalize}`]: ReadonlyPureSelectorToken$1; } : never; /** * Find the current value of a relation owned by a {@link join} * @param token - The token of the join * @param key - The key of the relation to find * @returns * A {@link JoinStates} interface to access the relation * @overload Default */ declare function findRelations(token: JoinToken, key: A | B): JoinStates; /** * Change one or multiple relations owned by a {@link join} * @param token - The token of the join * @param change - A function that takes a {@link Junction} interface to edit the relations */ declare function editRelations(token: JoinToken, change: (relations: Junction) => void): void; /** * @param token - The token of the join * @returns * A {@link MutableAtomFamilyToken} to access the internal relations */ declare function getInternalRelations(token: JoinToken): MutableAtomFamilyToken$1 | UList, A | B>; declare function getInternalRelations(token: JoinToken, split: `split`): [atob: MutableAtomFamilyToken$1, A>, btoa: MutableAtomFamilyToken$1, B>]; //#endregion //#region src/main/logger.d.ts declare const LOGGER_ICON_DICTIONARY: { readonly "๐Ÿ”จ": "Create state"; readonly "๐Ÿ› ๏ธ": "Install state into store"; readonly "๐Ÿ‘ช": "Family member added"; readonly "๐Ÿ”ฅ": "Family member deleted"; readonly "๐Ÿ“ƒ": "Copy mutable"; readonly "๐Ÿ“–": "Read from cache"; readonly "๐Ÿ“": "Write to cache"; readonly "โ”": "Cache miss"; readonly "โœจ": "Value derived"; readonly "โญ": "Value set"; readonly "โญ•": "Operation start"; readonly "๐Ÿ”ด": "Operation complete"; readonly "๐Ÿšซ": "Operation blocked"; readonly "๐ŸŸข": "Operation unblocked"; readonly "๐Ÿ—‘": "Evict cached value"; readonly "๐Ÿงน": "Prepare to evict"; readonly "๐Ÿงฎ": "Computing selector"; readonly "๐Ÿ”Œ": "Register direct dependency"; readonly "๐Ÿ”": "Discover root"; readonly "๐Ÿ“": "Stow update"; readonly "๐Ÿ›ซ": "Begin transaction"; readonly "๐Ÿ›„": "Apply transaction"; readonly "๐Ÿ›ฌ": "Complete transaction"; readonly "๐Ÿ’ฅ": "Transaction caught error"; readonly "๐Ÿช‚": "Abort transaction"; readonly "โŒ›": "Timeline event fully captured"; readonly "โฉ": "Timeline redo"; readonly "โช": "Timeline undo"; readonly "โญ๏ธ": "Transaction redo"; readonly "โฎ๏ธ": "Transaction undo"; readonly "โณ": "Timeline event partially captured"; readonly "โธ๏ธ": "Time-travel complete"; readonly "๐Ÿงผ": "Timeline cleared"; readonly "๐Ÿ’ฃ": "Dangerous action likely to cause bad errors down the line"; readonly "โ—": "Dangerous action unless in development mode"; readonly "โŒ": "Conflict prevents attempted action"; readonly "๐Ÿž": "Possible bug in AtomIO"; readonly "๐Ÿ’": "Advice and guidance to the developer"; readonly "๐Ÿ‘€": "Subscription added"; readonly "๐Ÿ™ˆ": "Subscription canceled"; readonly "๐Ÿ“ข": "Notify subscribers"; readonly "๐Ÿ›ฐ๏ธ": "Server socket"; readonly "๐Ÿ“ก": "Client socket"; readonly "๐Ÿ‘": "Successful operation"; }; type LoggerIcon = keyof typeof LOGGER_ICON_DICTIONARY; type EntityDenomination = `atom_family` | `atom` | `key` | `mutable_atom_family` | `mutable_atom` | `readonly_held_selector_family` | `readonly_held_selector` | `readonly_pure_selector_family` | `readonly_pure_selector` | `socket` | `state` | `timeline` | `timeline_family` | `transaction` | `unknown` | `user` | `writable_held_selector_family` | `writable_held_selector` | `writable_pure_selector_family` | `writable_pure_selector`; declare const PRETTY_ENTITY_NAMES: Record; declare const LOG_LEVELS: readonly ["info", "warn", "error"]; type LogLevel = (typeof LOG_LEVELS)[number]; type LogFn = (icon: LoggerIcon, denomination: EntityDenomination, tokenKey: string, message: string, ...rest: unknown[]) => void; type LogFilter = (...params: Parameters) => Parameters | boolean; type Logger = Record; declare const simpleLog: (logLevel: keyof Logger, prefix?: string) => LogFn; declare const simpleLogger: Logger; declare class AtomIOLogger implements Logger { logLevel: `error` | `info` | `warn` | null; filter: LogFilter | undefined; private readonly logger; constructor(logLevel: `error` | `info` | `warn` | null, filter?: LogFilter, logger?: Logger); error: LogFn; info: LogFn; warn: LogFn; } //#endregion //#region src/main/not-found-error.d.ts declare class NotFoundError extends Error { constructor(token: AtomIOToken, storeName: string); } //#endregion //#region src/main/reset-state.d.ts /** * Set the value of a state into the implicit store back to its default value. * @param token - An atom or writable selector token. * @overload Default * @default */ declare function resetState(token: WritableToken): void; /** * Set the value of a state into the implicit store back to its default value. * @param token - An atom family or writable selector family token. * @param key - The unique key of the state to set. * @overload Streamlined */ declare function resetState(token: WritableFamilyToken, key: K): void; //#endregion //#region src/main/set-state.d.ts /** * A function that sets the value of a state. * @param oldValue - The current value of the state. * @returns * The new value of the state. */ type Setter = (oldValue: T) => T; /** * Set the value of a state into the implicit store. * @param token - An atom or writable selector token. * @param value - The new value of the state. * @overload Default * @default */ declare function setState(token: WritableToken, value: Setter | TT): void; /** * Set the value of a state into the implicit store. * @param token - An atom family or writable selector family token. * @param key - The unique key of the state to set. * @param value - The new value of the state. * @overload Streamlined */ declare function setState(token: WritableFamilyToken, key: NoInfer, value: Setter | TT): void; //#endregion //#region src/main/transaction.d.ts type ReaderToolkit = Pick & { relations: Pick; }; type WriterToolkit = Pick; type ActorToolkit = Readonly<{ get: typeof getState; set: typeof setState; reset: typeof resetState; find: typeof findState; json: >(state: MutableAtomToken) => WritablePureSelectorToken>; dispose: typeof disposeState; run: typeof runTransaction; env: () => EnvironmentData; relations: RelationsToolkit; }>; type RelationsToolkit = { edit: typeof editRelations; find: typeof findRelations; internal: typeof getInternalRelations; }; type Read = (toolkit: ReaderToolkit, ...parameters: Parameters) => ReturnType; type Write = (toolkit: WriterToolkit, ...parameters: Parameters) => ReturnType; type Transact = (toolkit: ActorToolkit, ...parameters: Parameters) => ReturnType; type TransactionIO> = Token extends TransactionToken ? F : never; type TransactionOptions = { /** The unique identifier of the transaction */ key: string; /** The operation to perform */ do: Transact; }; /** * Create a transaction, a mechanism for batching updates multiple states in a single, all-or-nothing operation * @param options - {@link TransactionOptions} * @returns A reference to the transaction created: a {@link TransactionToken} */ declare function transaction(options: TransactionOptions): TransactionToken; /** * Execute a {@link transaction} * @param token - A {@link TransactionToken} * @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated * @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters */ declare function runTransaction(token: TransactionToken, id?: string): (...parameters: Parameters) => ReturnType; /** * Undo a transaction on every timeline where it is the current head. * * Timelines that have moved elsewhere are left unchanged. If `id` is omitted, * the most recent eligible instance is used. * * @param token - The transaction to undo. * @param id - The optional identifier of a specific transaction instance. */ declare function undoTransaction(token: TransactionToken, id?: string): void; /** * Redo a transaction on every timeline where it is the next head. * * Timelines that have moved elsewhere are left unchanged. If `id` is omitted, * the oldest eligible instance is used. * * @param token - The transaction to redo. * @param id - The optional identifier of a specific transaction instance. */ declare function redoTransaction(token: TransactionToken, id?: string): void; //#endregion //#region src/main/selector.d.ts type WritablePureSelectorOptions = { /** The unique identifier of the selector */ key: string; /** For each instantiated selector, a function that computes its value */ get: Read<() => T>; /** For each instantiated selector, a function that sets its value */ set: Write<(newValue: T) => void>; /** The classes of errors that might be thrown when deriving the atom's default value */ catch?: readonly Ctor[]; }; type ReadonlyPureSelectorOptions = { /** The unique identifier of the selector */ key: string; /** For each instantiated selector, a function that computes its value */ get: Read<() => T>; /** The classes of errors that might be thrown when deriving the atom's default value */ catch?: readonly Ctor[]; }; type ReadonlyHeldSelectorOptions = { /** The unique identifier of the selector */ key: string; /** For each instantiated selector, a constant reference to a value that will not be replaced */ const: T; /** For each instantiated selector, a function that computes its value */ get: Read<(permanent: T) => void>; }; type WritableHeldSelectorOptions = { /** The unique identifier of the selector */ key: string; /** For each instantiated selector, a constant reference to a value that will not be replaced */ const: T; /** For each instantiated selector, a function that computes its value */ get: Read<(permanent: T) => void>; /** For each instantiated selector, a function that sets its value */ set: Write<(newValue: T) => void>; }; /** * Declare a selector. The value of a selector should depend * on the value of atoms or other selectors in the store, and * should be recycled when a root atom of the selector is set. * * A held selector's value must be some object. * The reference to that object is permanent and will not be replaced. * * A writable selector can be "set" to a new value. * It is strongly advised to set its dependencies to values * that would produce the new value of the selector. * * @param options - {@link WritableHeldSelectorOptions}. * @returns * The token for your selector. * @overload WritableHeld */ declare function selector(options: WritableHeldSelectorOptions): WritableHeldSelectorToken; /** * Declare a selector. The value of a selector should depend * on the value of atoms or other selectors in the store, * and should be recycled when a root atom of the selector is set. * * A held selector's value must be some object. * The reference to that object is permanent and will not be replaced. * * A readonly selector can be "gotten" but not "set". * * @param options - {@link ReadonlyHeldSelectorOptions}. * @returns * The token for your selector. * @overload ReadonlyHeld */ declare function selector(options: ReadonlyHeldSelectorOptions): ReadonlyHeldSelectorToken; /** * Declare a selector. The value of a selector should depend * on the value of atoms or other selectors in the store. * * A pure selector's current value is evicted from the store * in order to be garbage collected when a root atom of the selector is set. * * A writable selector can be "set" to a new value. * It is strongly advised to set its dependencies to values * that would produce the new value of the selector. * * @param options - {@link TransientWritableSelectorOptions}. * @returns * The token for your selector. * @overload WritablePure */ declare function selector(options: WritablePureSelectorOptions): WritablePureSelectorToken; /** * Declare a selector. The value of a selector should depend * on the value of atoms or other selectors in the store. * * A pure selector's current value is evicted from the store * in order to be garbage collected when a root atom of the selector is set. * * A readonly selector can be "gotten" but not "set". * * @param options - {@link ReadonlyPureSelectorOptions}. * @returns * The token for your selector. * @overload ReadonlyPure */ declare function selector(options: ReadonlyPureSelectorOptions): ReadonlyPureSelectorToken; type WritablePureSelectorFamilyOptions = { /** The unique identifier of the family */ key: string; /** For each instantiated family member, a function that computes its value */ get: (key: K) => Read<() => T>; /** For each instantiated family member, a function that sets its value */ set: (key: K) => Write<(newValue: T) => void>; /** The classes of errors that might be thrown when deriving the atom's default value */ catch?: readonly Ctor[]; }; type ReadonlyPureSelectorFamilyOptions = { /** The unique identifier of the family */ key: string; /** For each instantiated family member, a function that computes its value */ get: (key: K) => Read<() => T>; /** The classes of errors that might be thrown when deriving the atom's default value */ catch?: readonly Ctor[]; }; type WritableHeldSelectorFamilyOptions = { /** The unique identifier of the family */ key: string; /** For each instantiated family member, a constant reference to a value that will not be replaced */ const: (key: K) => T; /** For each instantiated family member, a function that computes its value */ get: (key: K) => Read<(permanent: T) => void>; /** For each instantiated family member, a function that sets its value */ set: (key: K) => Write<(newValue: T) => void>; }; type ReadonlyHeldSelectorFamilyOptions = { /** The unique identifier of the family */ key: string; /** For each instantiated family member, a constant reference to a value that will not be replaced */ const: (key: K) => T; /** For each instantiated family member, a function that computes its value */ get: (key: K) => Read<(permanent: T) => void>; }; /** * Create a family of selectors, allowing for the dynamic creation and disposal of selectors. * * The value of a held selector should depend on the value of atoms or other selectors in the store, * and should be recycled when a root atom of the selector is set. * * A held selector's value must be some object. * The reference to that object is permanent and will not be replaced. * * A writable selector can be "set" to a new value. * It is advised to set its dependencies to values * that would produce the new value of the selector. * * @param options - {@link WritableHeldSelectorFamilyOptions}. * @returns * A reference to the selector family created: a {@link WritableHeldSelectorFamilyToken} * @overload WritableHeld */ declare function selectorFamily(options: WritableHeldSelectorFamilyOptions): WritableHeldSelectorFamilyToken; /** * Create a family of selectors, allowing for the dynamic creation and disposal of selectors. * * The value of a held selector should depend on the value of atoms or other selectors in the store, * and should be recycled when a root atom of the selector is set. * * A held selector's value must be some object. * The reference to that object is permanent and will not be replaced. * * A readonly selector can be "gotten" but not "set". * * @param options - {@link ReadonlyHeldSelectorFamilyOptions}. * @returns * A reference to the selector family created: a {@link ReadonlyHeldSelectorFamilyToken} * @overload ReadonlyHeld */ declare function selectorFamily(options: ReadonlyHeldSelectorFamilyOptions): ReadonlyHeldSelectorFamilyToken; /** * Create a family of selectors, allowing for the dynamic creation and disposal of selectors. * * The value of a selector should depend on the value of atoms or other selectors in the store. * * A pure selector's current value is evicted from the store * in order to be garbage collected when a root atom of the selector is set. * * A writable selector can be "set" to a new value. * It is advised to set its dependencies to values * that would produce the new value of the selector. * * @param options - {@link TransientWritableSelectorFamilyOptions}. * @returns * A reference to the selector family created: a {@link TransientWritableSelectorFamilyToken} * @overload WritablePure */ declare function selectorFamily(options: WritablePureSelectorFamilyOptions): WritablePureSelectorFamilyToken; /** * Create a family of selectors, allowing for the dynamic creation and disposal of selectors. * * The value of a selector should depend on the value of atoms or other selectors in the store. * * A pure selector's current value is evicted from the store * in order to be garbage collected when a root atom of the selector is set. * * A readonly selector can be "gotten" but not "set". * * @param options - {@link ReadonlyPureSelectorFamilyOptions}. * @returns * A reference to the selector family created: a {@link ReadonlyPureSelectorFamilyToken} * @overload ReadonlyPure */ declare function selectorFamily(options: ReadonlyPureSelectorFamilyOptions): ReadonlyPureSelectorFamilyToken; //#endregion //#region src/main/silo.d.ts declare class Silo { store: RootStore; atom: typeof atom; mutableAtom: typeof mutableAtom; atomFamily: typeof atomFamily; mutableAtomFamily: typeof mutableAtomFamily; selector: typeof selector; selectorFamily: typeof selectorFamily; transaction: typeof transaction; timeline: typeof timeline; /** {@link timelineFamily}, bound to this Silo's store. */ timelineFamily: typeof timelineFamily; findState: typeof findState$1; /** {@link findTimeline}, bound to this Silo's store. */ findTimeline: typeof findTimeline; getState: typeof getState; setState: typeof setState; resetState: typeof resetState; disposeState: typeof disposeState; subscribe: typeof subscribe; undo: typeof undo; redo: typeof redo; clearTimeline: typeof clearTimeline; /** {@link inspectTimeline}, bound to this Silo's store. */ inspectTimeline: typeof inspectTimeline; /** {@link disposeTimeline}, bound to this Silo's store. */ disposeTimeline: typeof disposeTimeline; runTransaction: typeof runTransaction; /** {@link undoTransaction}, bound to this Silo's store. */ undoTransaction: typeof undoTransaction; /** {@link redoTransaction}, bound to this Silo's store. */ redoTransaction: typeof redoTransaction; install: (tokens: AtomIOToken[], store?: RootStore) => void; constructor(config: Store[`config`], fromStore?: Store | null); } //#endregion //#region src/main/subscribe.d.ts type UpdateHandler = (update: StateUpdate) => void; type TransactionUpdateHandler = (data: TransactionOutcomeEvent>) => void; /** * Subscribe to a state in the implicit store * @param token - The token of the state to subscribe to * @param handleUpdate - A function that will be called when the state is updated * @param key - A unique key for the subscription. If not provided, a random key will be generated. * @returns A function that can be called to unsubscribe from the state * @overload State */ declare function subscribe(token: ReadableToken, handleUpdate: UpdateHandler, key?: string): () => void; /** * Subscribe to a transaction in the implicit store * @param token - The token of the transaction to subscribe to * @param handleUpdate - A function that will be called when the transaction succeeds * @param key - A unique key for the subscription. If not provided, a random key will be generated. * @returns A function that can be called to unsubscribe from the transaction * @overload Transaction */ declare function subscribe(token: TransactionToken, handleUpdate: TransactionUpdateHandler, key?: string): () => void; /** * Subscribe to a timeline in the implicit store * @param token - The token of the timeline to subscribe to * @param handleUpdate - A function that will be called when a new update is available * @param key - A unique key for the subscription. If not provided, a random key will be generated. * @returns A function that can be called to unsubscribe from the timeline * @overload Timeline */ declare function subscribe(token: TimelineToken, handleUpdate: (update: TimelineUpdate) => void, key?: string): () => void; /** * Subscribe to a timeline-family member in the implicit store, creating it if needed. * @param family - A {@link TimelineFamilyToken}. * @param memberKey - The key of the timeline-family member. * @param handleUpdate - A function that will be called when a new update is available. * @param subscriptionKey - A unique key for the subscription. If not provided, a random key will be generated. * @returns A function that can be called to unsubscribe from the timeline-family member. * @overload Timeline Family Member */ declare function subscribe(family: TimelineFamilyToken, memberKey: NoInfer, handleUpdate: (update: TimelineUpdate) => void, subscriptionKey?: string): () => void; //#endregion //#region src/main/index.d.ts /** * Loadable is used to type atoms or selectors that may at some point be initialized to or set to a {@link Promise}. * * When a Promise is cached as the value of a state in atom.io, that state will be automatically set to the resolved value of the Promise when it is resolved. * * As a result, we consider any state that can be a set to a Promise to be a "loadable" state, whose value may or may not be a Promise at any given time. */ type Loadable = Promise | T; //#endregion export { ActorToolkit, type AtomCreationEvent, type AtomDisposalEvent, AtomEffect, type AtomFamilyToken, AtomIOLogger, type AtomIOToken, type AtomLifecycleEvent, AtomOnly, type AtomToken, type AtomUpdateEvent, Effectors, EntityDenomination, type FamilyMetadata, type HeldSelectorFamilyToken, type HeldSelectorToken, JoinOptions, JoinStates, JoinToken, LOG_LEVELS, Loadable, LogFilter, LogFn, LogLevel, Logger, LoggerIcon, type MoleculeCreationEvent, type MoleculeDisposalEvent, type MoleculeTransferEvent, MutableAtomFamilyOptions, type MutableAtomFamilyToken, MutableAtomOptions, type MutableAtomToken, NotFoundError, PRETTY_ENTITY_NAMES, type PureSelectorFamilyToken, type PureSelectorToken, Read, type ReadableFamilyToken, type ReadableToken, ReaderToolkit, ReadonlyHeldSelectorFamilyOptions, type ReadonlyHeldSelectorFamilyToken, ReadonlyHeldSelectorOptions, type ReadonlyHeldSelectorToken, ReadonlyPureSelectorFamilyOptions, type ReadonlyPureSelectorFamilyToken, ReadonlyPureSelectorOptions, type ReadonlyPureSelectorToken, type ReadonlySelectorFamilyToken, type ReadonlySelectorToken, RegularAtomFamilyOptions, type RegularAtomFamilyToken, RegularAtomOptions, type RegularAtomToken, RelationsToolkit, type SelectorFamilyToken, type SelectorToken, type SelectorUpdateSubEvent, Setter, Silo, type StateUpdate, type TimelineCullEvent, TimelineEffect, TimelineEffectors, type TimelineEvent, TimelineFamilyOptions, TimelineFamilyScope, type TimelineFamilyToken, TimelineInspection, TimelineManageable, TimelineOptions, TimelineRecordEvent, type TimelineSelectorUpdateEvent, type TimelineToken, type TimelineUpdate, type TokenType, Transact, TransactionIO, TransactionOptions, type TransactionOutcomeEvent, type TransactionSubEvent, type TransactionToken, TransactionUpdateHandler, UpdateHandler, type ViewOf, type WritableFamilyToken, WritableHeldSelectorFamilyOptions, type WritableHeldSelectorFamilyToken, WritableHeldSelectorOptions, type WritableHeldSelectorToken, WritablePureSelectorFamilyOptions, type WritablePureSelectorFamilyToken, WritablePureSelectorOptions, type WritablePureSelectorToken, type WritableSelectorFamilyToken, type WritableSelectorToken, type WritableToken, Write, WriterToolkit, atom, atomFamily, clearTimeline, disposeState, disposeTimeline, editRelations, findRelations, findState, findTimeline, getInternalRelations, getJsonToken, getState, inspectTimeline, join, mutableAtom, mutableAtomFamily, redo, redoTransaction, resetState, runTransaction, scopeFamily, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, timelineFamily, transaction, undo, undoTransaction }; //# sourceMappingURL=index.d.ts.map