UNPKG

@omnia/fx

Version:

Provide Omnia Fx typings and tooling for clientside Omnia development.

151 lines (150 loc) • 10.9 kB
import { InstanceLifetimes, GuidValue, StoreDefintion as OmniaStoreDefinition, StateMutation, MutatableState, IMessageBusSubscriptionHandler } from "../models"; export declare enum StoreLogTypes { mutation = "Mutation", action = "Action" } export interface StoreLog { id: GuidValue; name: string; type: StoreLogTypes; storeId: GuidValue; storeName: string; createdAt: Date; object: StateMutation<any>; } export interface StateMutationLog { oldState: string; newState: string; } export interface StateActionLog { func: any; } export type MapOnCommitToCommit<T extends Function> = T extends (...args: infer U) => void ? (...args: U) => IMessageBusSubscriptionHandler : T; export type MapActionOnDispatching<T extends Function> = T extends (...args: infer U) => Promise<infer Y> ? (...args: U) => void : never; export type MapActionOnDispatched<T extends Function> = T extends (...args: infer U) => Promise<infer Y> ? (result: Y, ...args: U) => void : never; export type MapActionOnFailure<T extends Function> = T extends (...args: infer U) => Promise<infer Y> ? (failureReason: any, ...args: U) => void : never; export declare class StoreLogger { private _logState; enabled: boolean; constructor(logState: Array<StoreLog>); add(id: GuidValue, name: string, type: StoreLogTypes, storeId: GuidValue, storeName: string, object: StateMutationLog): void; enable(): void; disable(): void; get log(): Array<StoreLog>; } export declare abstract class Store { private static _vm; private static _state; private static _log; private static _logger; static get logging(): StoreLogger; private _storeDefinition; private _disposed; constructor(storeDefinition?: Omit<OmniaStoreDefinition, "id">); protected get id(): GuidValue; /** * Triggers when the store is ready to be used * */ protected abstract onActivated(): any; /** * Triggers when the store is being disposed * */ protected onDisposing(): void; get isDisposed(): boolean; /** * Creates a new state * */ protected state<T>(initialValue?: T): StoreState<T>; /** * Creates a new action * */ protected action<PromiseType, Dispatcher extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6, arg7: Arg7, arg8: Arg8, arg9: Arg9, arg10: Arg10) => Promise<PromiseType>, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; protected action<PromiseType, Dispatcher extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6, arg7: Arg7, arg8: Arg8, arg9: Arg9) => Promise<PromiseType>, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; protected action<PromiseType, Dispatcher extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6, arg7: Arg7, arg8: Arg8) => Promise<PromiseType>, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; protected action<PromiseType, Dispatcher extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6, arg7: Arg7) => Promise<PromiseType>, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; protected action<PromiseType, Dispatcher extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6) => Promise<PromiseType>, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; protected action<PromiseType, Dispatcher extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5) => Promise<PromiseType>, Arg1, Arg2, Arg3, Arg4, Arg5>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; protected action<PromiseType, Dispatcher extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4) => Promise<PromiseType>, Arg1, Arg2, Arg3, Arg4>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; protected action<PromiseType, Dispatcher extends (arg1: Arg1, arg2: Arg2, arg3: Arg3) => Promise<PromiseType>, Arg1, Arg2, Arg3>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; protected action<PromiseType, Dispatcher extends (arg1: Arg1, arg2: Arg2) => Promise<PromiseType>, Arg1, Arg2>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; protected action<PromiseType, Dispatcher extends (arg1: Arg1) => Promise<PromiseType>, Arg1>(action: Dispatcher): StoreAction<PromiseType, MapActionOnDispatching<Dispatcher>, MapActionOnDispatched<Dispatcher>, MapActionOnFailure<Dispatcher>, Dispatcher>; /** * Creates a new mutation * */ protected mutation<Mutation extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6, arg7: Arg7, arg8: Arg8, arg9: Arg9, arg10: Arg10) => void, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; protected mutation<Mutation extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6, arg7: Arg7, arg8: Arg8, arg9: Arg9) => void, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; protected mutation<Mutation extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6, arg7: Arg7, arg8: Arg8) => void, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; protected mutation<Mutation extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6, arg7: Arg7) => void, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; protected mutation<Mutation extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5, arg6: Arg6) => void, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; protected mutation<Mutation extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4, arg5: Arg5) => void, Arg1, Arg2, Arg3, Arg4, Arg5>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; protected mutation<Mutation extends (arg1: Arg1, arg2: Arg2, arg3: Arg3, arg4: Arg4) => void, Arg1, Arg2, Arg3, Arg4>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; protected mutation<Mutation extends (arg1: Arg1, arg2: Arg2, arg3: Arg3) => void, Arg1, Arg2, Arg3>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; protected mutation<Mutation extends (arg1: Arg1, arg2: Arg2) => void, Arg1, Arg2>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; protected mutation<Mutation extends (arg1: Arg1) => void, Arg1>(mutation: Mutation): StoreMutation<Mutation, MapOnCommitToCommit<Mutation>>; /** * Registers a store with a lifetime option * */ static register<T extends Store>(type: T, lifetime: InstanceLifetimes): void; /** * Registers a store as transient * */ static registerAsTransient<T extends Store>(type: T): void; /** * Gets an instance of a registered store * */ static get<T extends Store>(type: T): T; private static registerInternal; private static initNewStore; private static ensure; } export declare class StoreState<T> { private _val; private _propName; private _afterMutateSubscription; private _beforeMutateSubscription; private _globalState; private _storeDefinition; constructor(initialState: T, globalState: any); private init; get name(): string; get state(): T; mutate(state: T | ((mutatableValue: MutatableState<T>) => void)): void; get onMutating(): (fn: (obj: StateMutation<T>) => void) => IMessageBusSubscriptionHandler; get onMutated(): (fn: (obj: StateMutation<T>) => void) => IMessageBusSubscriptionHandler; private ensureInitialized; } export declare class StoreAction<PromiseResultType, OnDispatching extends MapActionOnDispatching<D>, OnDispatched extends MapActionOnDispatched<D>, OnFailure extends MapActionOnFailure<D>, D extends (...args: any[]) => Promise<PromiseResultType>> { dispatch: D; private _onDisplatchingSubscription; private _onCompletedSubscription; private _onFailureSubscription; private _storeDefinition; constructor(dispatcher: D, storeDefinition: OmniaStoreDefinition); /** * Invoked directly when calling action dispath * @param fn - handler function on the format (args...- any number of arguments passed to the dispatcher) */ onDispatching(fn: OnDispatching): IMessageBusSubscriptionHandler; /** * Invoked when the action completes, i.e. the promise is resolved * @param fn - handler function on the format (result- the data passed to promise resolver (or null), args...- any number of arguments passed to the dispatcher) * result - the return type of the action Promise<result> */ onDispatched(fn: OnDispatched): IMessageBusSubscriptionHandler; /** * Invoked on any failure for this action * @param fn - handler function on the format (reason- the reject reason, args...- any number of arguments passed to the dispatcher) * reason - the reason passed to reject of action promise * */ onFailure(fn: OnFailure): IMessageBusSubscriptionHandler; } export declare class StoreMutation<T extends Function, CommitFunc extends Function> { commit: CommitFunc; private _afterMutateSubscription; private _beforeMutateSubscription; private _storeDefinition; constructor(mutation: T, storeDefinition: OmniaStoreDefinition); onCommiting(fn: T): IMessageBusSubscriptionHandler; onCommited(fn: T): IMessageBusSubscriptionHandler; }