import { EventEmitter } from '../utils/emitter'; import { HashFunction } from '../utils/hash'; import { SerializedStore } from '../utils/inspect'; import { Matcher, MatcherFactory } from './matchers'; import { Stream } from './stream'; export declare const CONTEXT: unique symbol; export declare const GRAPH_NODE: unique symbol; export declare const GRAPH_OPERATION: unique symbol; export declare const GRAPH_ACTION: unique symbol; export declare const NODE_DEFINITION: unique symbol; export declare const NODE_TYPE: unique symbol; export declare const OPERATION_TYPE: unique symbol; export declare const SCOPE: unique symbol; export declare const MATCHER: unique symbol; export declare const PROXIED_NODE: unique symbol; export declare const PROXIED_NODE_DEFINITION: unique symbol; export declare type NodeLike = any; export declare type NodeType = GraphOperation> = StaticNodeType | DynamicNodeType; export declare type NodeName = string; export declare type NodeProperties = {}; export declare type SerializableObject = NodeDefinition | GraphOperation | Matcher; export declare type SerializedNodeProperties = any; export declare type SerializedOperationProperties = any; export interface StaticNodeType { [NODE_TYPE]: true; name: T; hash: HashFunction

; shape: Matcher

; serialize: false | undefined | ((value: P, serialize: (value: SerializableObject) => T) => V); deserialize: false | undefined | ((properties: V, deserialize: (node: T) => SerializableObject) => P); is: (value: GraphNode) => value is GraphNode; getType?: (properties: P, getType: (value: any) => string) => string; } export interface StaticNodeDefinition = StaticNodeType> extends NodeDefinition { } export interface StaticGraphNode = StaticNodeType> extends GraphNode { } export declare type DynamicNodeType = GraphOperation> = StatelessNodeType | StatefulNodeType; export interface DynamicNodeDefinition = GraphOperation, N extends DynamicNodeType = DynamicNodeType> extends NodeDefinition { } export interface DynamicGraphNode = GraphOperation, N extends DynamicNodeType = DynamicNodeType> extends GraphNode { } export interface StatelessNodeType = GraphOperation> extends StaticNodeType { operations: { [K in M]: StatelessOperationHandler & O>; }; } export interface StatelessNodeDefinition = StatelessNodeType> extends NodeDefinition { } export interface StatelessGraphNode = StatelessNodeType> extends GraphNode { } export interface StatefulNodeType = GraphOperation> extends StaticNodeType { state: Matcher; hashState: HashFunction; getInitialState(properties: P): S; operations: { [K in M]: StatefulOperationHandler & O>; }; onSubscribe?(node: StatefulGraphNode): void; onUnsubscribe?(node: StatefulGraphNode): void; } export interface StatefulNodeDefinition = GraphOperation, N extends StatefulNodeType = StatefulNodeType> extends NodeDefinition { } export interface StatefulGraphNode = GraphOperation, N extends StatefulNodeType = StatefulNodeType> extends GraphNode { } export declare type OperationHandler = GraphOperation> = StatelessOperationHandler | StatefulOperationHandler; export interface StatelessOperationHandler = GraphOperation> { cacheable: boolean; getDependencies: (definition: NodeDefinition, operation: O) => Array; getContextDependencies: (node: NodeDefinition, operation: O) => Array; run(node: GraphNode, operation: O, dependencies: Array, context: Array, state: undefined): GraphNode | GraphAction; } export interface StatefulOperationHandler = GraphOperation> { cacheable: boolean; getDependencies(node: NodeDefinition, operation: O): Array; getContextDependencies(node: NodeDefinition, operation: O): Array; run(node: GraphNode, operation: O, dependencies: Array, context: Array, state: S): GraphNode | GraphAction; onInvalidate?(node: StatefulGraphNode>, operation: O): void; onSubscribe?(node: StatefulGraphNode>, operation: O): void; onUpdate?(node: StatefulGraphNode>, operation: O, dependencies: Array, context: Array, previousDependencies: Array | undefined): void; onUnsubscribe?(node: StatefulGraphNode>, operation: O): void; } export declare type NodeState = any; export declare type NodeData = { [key: string]: any; }; export interface NodeExecutionContext { getData(): Partial; setData(update: ValueUpdater): Partial; getState(): S; setState(update: ValueUpdater, callback?: (state: S) => void): void; retain(): number; release(): number; } export declare type ValueUpdater = Partial<{ [key in keyof T]: T[key]; }> | ((previous: T) => T); export interface NodeDependencyUntilCondition { predicate: (node: GraphNode) => boolean; errorMessage?: (node: GraphNode) => string; } export interface ResolveOptions { until?: NodeDependencyUntilCondition; acceptNil?: boolean; } export interface DependencyOptions { allowErrors?: boolean; allowPending?: boolean; acceptNil?: boolean; until?: NodeDependencyUntilCondition; once?: boolean; invalidate?: boolean; } export interface NodeDependency extends DependencyOptions { target: NodeDefinition | GraphNode; } export interface Dependency { target: NodeDefinition | GraphNode; operation: GraphOperation; allowErrors: boolean; allowPending: boolean; invalidate: boolean; } export interface RequiredContextDependency extends DependencyOptions { name: string | symbol; required: true | string | ((node: GraphNode, name: string | symbol) => string); } export interface OptionalContextDependency extends DependencyOptions { name: string | symbol; required: false; defaultValue: NodeDefinition; } export declare type ContextDependency = RequiredContextDependency | OptionalContextDependency; export interface NodeDefinition = NodeType> { [NODE_DEFINITION]: true; id: string; type: N; properties: P; } export declare type SerializedNodeDefinition = NodeType> = { $type: N['name']; data: V; }; export interface GraphNode = NodeType> { [GRAPH_NODE]: true; id: string; definition: NodeDefinition; scope: Scope; context: Context; } export declare type NodeStream = Stream; export interface Scope { [SCOPE]: true; id: string; globalEvents: MusterEventSource; store: Store; events: MusterEventSource; parent: Scope | undefined; onSubscribe: (() => void) | undefined; onUnsubscribe: (() => void) | undefined; } export interface Context { [CONTEXT]: true; id: string; root: Context; parent: Context | undefined; values: ContextValues; } export declare type ContextName = string; export declare type ContextValues = { [key in ContextName]: GraphNode; }; export interface OperationType { [OPERATION_TYPE]: true; name: N; shape: Matcher

; hash: HashFunction

; serialize: false | undefined | ((value: P, serialize: (value: SerializableObject) => T) => S); deserialize: false | undefined | ((value: S, deserialize: (value: T) => SerializableObject) => P); } export declare type OperationName = string; export declare type OperationProperties = {}; export interface GraphOperation = OperationType> { [GRAPH_OPERATION]: true; id: string; type: O; properties: P; } export declare type SerializedGraphOperation = OperationType> = { $operation: O['name']; id: string; data: P; }; export interface GraphAction = GraphOperation, N1 extends StaticNodeType = StaticNodeType, N2 extends DynamicNodeType = DynamicNodeType> { [GRAPH_ACTION]: true; id: string; node: StaticGraphNode | DynamicGraphNode; operation: GraphOperation; } export interface StaticGraphAction = StaticNodeType> { [GRAPH_ACTION]: true; id: string; node: StaticGraphNode; operation: GraphOperation; } export interface DynamicGraphAction = GraphOperation, N extends DynamicNodeType = DynamicNodeType> { [GRAPH_ACTION]: true; id: string; node: DynamicGraphNode; operation: GraphOperation; } export declare type ChildKey = any; export interface Params { [id: string]: ChildKey; } export interface CreateChildScopeOptions { retain: () => number; release: () => number; redispatch?: ((event: MusterEvent) => MusterEvent | undefined) | true; } export interface Store { subscribe(node: GraphNode, operation: GraphOperation, callback: UpdateCallback, options?: { debug?: boolean; }): DisposeCallback; retain(node: GraphNode, operation?: GraphOperation): number; release(node: GraphNode, operation?: GraphOperation): number; invalidate(node: GraphNode, operation?: GraphOperation): boolean; getNodeData(node: StatefulGraphNode): D | undefined; setNodeData(node: StatefulGraphNode, data: D): void; getNodeState(node: StatefulGraphNode): S | undefined; setNodeState(node: StatefulGraphNode, state: S): void; disposeScope(scope: Scope): void; inspect(): SerializedStore; } export declare type UpdateCallback = (value: GraphNode) => void; export declare type DisposeCallback = () => void; export interface MusterEvent { type: T; payload: V; } export declare type MusterEventName = string; export declare type MusterEventPayload = any; export declare type MusterEventSource = EventEmitter>; export declare type MusterTypeName = string; export interface MusterType { name: N; deserialize: (value: SerializedMusterTypeData | undefined, deserialize: (value: any) => any) => Matcher; serialize?: (value: Matcher, serialize: (value: any) => any) => SerializedMusterTypeData; } export interface SerializedMusterType { $musterType: string; data: SerializedMusterTypeData | undefined; } export declare type SerializedMusterTypeData = any; export declare type MusterTypeMap = { [name in MusterTypeName]: MusterType; }; export declare type NodeTypeMap = { [name in NodeName]: NodeType; }; export declare type OperationTypeMap = { [name in OperationName]: OperationType; }; export interface ProxiedNode { [PROXIED_NODE]: NodeDefinition | GraphNode; [PROXIED_NODE_DEFINITION]: NodeDefinition; } export declare function getProxiedNodeValue(value: ProxiedNode): NodeDefinition | GraphNode; export declare function getProxiedNodeDefinition(value: ProxiedNode): NodeDefinition; export declare function isProxiedNode(value: any): value is ProxiedNode; export declare function isScope(value: any): value is Scope; export declare function isNodeDefinition(value: any): value is NodeDefinition; export declare function isNodeType(value: any): value is NodeType; export declare function isGraphNode(value: any): value is GraphNode; export declare function isContext(value: any): value is Context; export declare function isOperationType(value: any): value is OperationType; export declare function isGraphOperation(value: any): value is GraphOperation; export declare function isGraphAction(value: any): value is GraphAction; export declare function isEvent(value: any): value is MusterEvent; export declare function isMatcher(value: any): value is Matcher; export declare function getMatcherType(matcher: Matcher): Matcher | MatcherFactory; export declare function getMatcherOptions(matcher: Matcher): P; export declare function createMatcher(name: string, match: ((value: any) => boolean), options?: P | undefined): Matcher; export declare function setUnitTestMatcher(matcher: (value: any) => boolean): void;