import { Realm, RealmNode, Subscription, UnsubscribeHandle } from './realm'; /** * The system interface is the runtime representation of a state management module, a record of nodes. */ export interface System { [key: string]: RealmNode; } /** * a SystemSpec is the result from a [[system]] call. To obtain the [[system]], pass the spec to [[init]]. * @typeParam Dependencies - The dependencies of the system. * @typeParam Constructor - The system constructor. */ export interface SystemSpec> { id: string; constructor: Constructor; dependencies: Dependencies; } /** @internal **/ export interface AnySystemSpec extends SystemSpec { id: string; } /** @internal **/ export type AnySystemSpecs = Array; /** @internal **/ export type SystemOfSpec = ReturnType; /** @internal **/ export type SSR = SystemOfSpec; /** @internal **/ export type SystemsFromSpecs = ST extends unknown[] ? SystemsFromSpecsRec : never; type SystemsFromSpecsRec = ST extends [infer Head, ...infer Tail] ? SystemsFromSpecsRec : never]> : Acc; /** * The system constructor is a function which initializes and connects nodes and returns them as a [[system]]. * If the [[system]] call specifies system dependencies, the constructor receives the dependencies as an array argument. */ export interface SystemConstructor { (r: Realm, dependencies: SystemsFromSpecs): System; } /** * Declare a new state management module (system). The constructor receives the realm and the dependencies as arguments. * @param constructor - The system constructor. * @param dependencies - The dependencies of the system - other systems. */ export declare function system, Constructor extends SystemConstructor>(constructor: Constructor, dependencies?: Dependencies): SystemSpec; type SystemKey = Extract; /** @internal */ export type ValuesForKeys[]> = K extends unknown[] ? ValuesForKeysRec : never; type ValuesForKeysRec, K extends unknown[], Acc extends unknown[]> = K extends [infer Head, ...infer Tail] ? ValuesForKeysRec ? R : never]> : Acc; /** @internal **/ export type SystemOfSpecs = Specs extends unknown[] ? SystemOfSpecsRec : Specs; type SystemOfSpecsRec = Specs extends [infer Head, ...infer Tail] ? SystemOfSpecsRec : never> : Acc; /** @internal */ export type LongTuple = [] | [K] | [K, K] | [K, K, K] | [K, K, K, K] | [K, K, K, K, K] | [K, K, K, K, K, K] | [K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K] | [K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K, K]; /** @internal */ export type SystemKeys = Extract> = LongTuple; /** @internal */ export type ValueForKey = S[K] extends RealmNode ? V : never; /** @internal */ export type SystemDict = { [K in keyof S]?: ValueForKey; }; /** @internal */ export type SystemKeysArray = Array; /** @internal */ export interface TypedRealm extends Pick { getKeyValues>(keys: K): ValuesForKeys; getKeyValue(key: K): ValueForKey; labels: S; pubKey(key: K, value: ValueForKey): void; pubKeys: (values: SystemDict) => void; subKey(key: K, subscription: Subscription>): UnsubscribeHandle; subKeys>(keys: K, subscription: Subscription>): UnsubscribeHandle; } /** @internal */ export declare function realmFactory>(...specs: Specs): TypedRealm>; /** @internal */ export type RealmFactory = () => TypedRealm; /** @internal */ export declare function getRealmFactory>(...specs: Specs): () => TypedRealm>; export {};