import { ThreadedClassConfig } from '../api';
export declare const DEFAULT_CHILD_FREEZE_TIME = 1000;
export declare const DEFAULT_RESTART_TIMEOUT = 1000;
export declare const DEFAULT_KILL_TIMEOUT = 1000;
export declare const DEFAULT_AUTO_RESTART_RETRY_COUNT = 1;
export declare const DEFAULT_AUTO_RESTART_RETRY_DELAY = 1000;
export declare type InitProps = Array<InitProp>;
export declare enum InitPropType {
    FUNCTION = "function",
    VALUE = "value"
}
export interface InitPropDescriptor {
    /** If the property is a part of the prototype (and how many levels deep) */
    inProto: number;
    enumerable: boolean;
    /** If the property has a getter */
    get: boolean;
    /** If the property has a setter */
    set: boolean;
    /** If the property is writable */
    writable: boolean;
    /** If the property is readable */
    readable: boolean;
}
export interface InitProp {
    type: InitPropType;
    key: string;
    descriptor: InitPropDescriptor;
}
/** Definitions of all messages between the child and parent */
export declare namespace Message {
    interface Base {
        messageType: 'instance' | 'child';
        cmdId: number;
    }
    export interface InstanceBase extends Base {
        messageType: 'instance';
        instanceId: string;
    }
    export interface ChildBase extends Base {
        messageType: 'child';
    }
    /** Containes definitions of messages sent from the parent process */
    export namespace To {
        type Any = Instance.Any | Child.Any;
        type AnyConstr = Instance.AnyConstr | Child.AnyConstr;
        /** Defines messages sent from the parent process to the child instance */
        namespace Instance {
            type AnyConstr = InitConstr | FcnConstr | ReplyConstr | SetConstr | KillConstr | CallbackConstr | PingConstr;
            type Any = Init | Fcn | Reply | Set | Kill | Callback | Ping;
            enum CommandType {
                INIT = "init",
                PING = "ping",
                FUNCTION = "fcn",
                REPLY = "reply",
                SET = "set",
                KILL = "kill",
                CALLBACK = "callback"
            }
            interface InitConstr {
                cmd: CommandType.INIT;
                modulePath: string;
                exportName: string;
                args: Array<ArgDefinition>;
                config: ThreadedClassConfig;
                parentPid: number;
            }
            /**
             * Initial message from parent to the child instance.
             * Child instance will reply with InitProps.
             * @see InitProps
             */
            type Init = InitConstr & InstanceBase;
            /**  */
            interface PingConstr {
                cmd: CommandType.PING;
            }
            /**
             * Just a ping, used to check if the child instance is alive.
             * Child instance will reply with null.
             */
            type Ping = PingConstr & InstanceBase;
            interface FcnConstr {
                cmd: CommandType.FUNCTION;
                fcn: string;
                args: Array<ArgDefinition>;
            }
            /**
             * Sent from parent process to child instance.
             * Calls a function/method on the child instance.
             * Child instance will reply with the result of the function call.
             */
            type Fcn = FcnConstr & InstanceBase;
            interface SetConstr {
                cmd: CommandType.SET;
                property: string;
                value: ArgDefinition;
            }
            /**
             * Sent from parent process to child instance.
             * Sets a property on the child instance.
             * Child instance will reply with the set value
             */
            type Set = SetConstr & InstanceBase;
            interface ReplyConstr {
                cmd: CommandType.REPLY;
                replyTo: number;
                reply?: any;
                error?: Error | string;
            }
            /**
             * Sent from parent process to child instance.
             * Contains a reply to a previous message sent from the child instance to the parent process.
             */
            type Reply = ReplyConstr & InstanceBase;
            interface KillConstr {
                cmd: CommandType.KILL;
            }
            /**
             * Sent from parent process to child instance.
             * A Kill command
             * Child instance will reply with null.
             */
            type Kill = KillConstr & InstanceBase;
            interface CallbackConstr {
                cmd: CommandType.CALLBACK;
                callbackId: string;
                args: Array<any>;
            }
            /**
             * Sent from parent process to child instance.
             * Calling a callback function. A "callback" is a function that has been sent to the parent process from the child instance.
             * Child instance will reply with null.
             */
            type Callback = CallbackConstr & InstanceBase;
        }
        /** Defines messages sent from the parent process to the child process */
        namespace Child {
            type AnyConstr = ReplyConstr | GetMemUsageConstr;
            type Any = Reply | GetMemUsage;
            enum CommandType {
                GET_MEM_USAGE = "get_mem_usage",
                REPLY = "reply"
            }
            interface GetMemUsageConstr {
                cmd: CommandType.GET_MEM_USAGE;
            }
            type GetMemUsage = GetMemUsageConstr & ChildBase;
            interface ReplyConstr {
                cmd: CommandType.REPLY;
                replyTo: number;
                reply?: any;
                error?: Error | string;
            }
            type Reply = ReplyConstr & ChildBase;
        }
    }
    /** Containes definitions of messages sent from the child process */
    export namespace From {
        type Any = Instance.Any | Child.Any;
        type AnyConstr = Instance.AnyConstr | Child.AnyConstr;
        /** Defines messages sent from the child instance to the parent process */
        namespace Instance {
            enum CommandType {
                CALLBACK = "callback",
                REPLY = "reply"
            }
            interface CallbackConstr {
                cmd: CommandType.CALLBACK;
                callbackId: string;
                args: Array<any>;
            }
            type Callback = CallbackConstr & InstanceBase;
            interface ReplyConstr {
                cmd: CommandType.REPLY;
                replyTo: number;
                reply?: any;
                error?: Error | string;
            }
            type Reply = ReplyConstr & InstanceBase;
            type AnyConstr = ReplyConstr | CallbackConstr;
            type Any = Reply | Callback;
        }
        /** Defines messages sent from the child process to the parent process */
        namespace Child {
            enum CommandType {
                LOG = "log",
                REPLY = "reply"
            }
            interface LogConstr {
                cmd: CommandType.LOG;
                log: Array<any>;
            }
            type Log = LogConstr & ChildBase;
            interface ReplyConstr {
                cmd: CommandType.REPLY;
                replyTo: number;
                reply?: any;
                error?: Error | string;
            }
            type Reply = ReplyConstr & ChildBase;
            type AnyConstr = ReplyConstr | LogConstr;
            type Any = Reply | Log;
        }
    }
    export {};
}
export declare type CallbackFunction = (e: Error | string | null, res?: ArgDefinition) => void;
export interface ArgDefinition {
    type: ArgumentType;
    original?: any;
    value: any;
}
declare enum ArgumentType {
    STRING = "string",
    NUMBER = "number",
    UNDEFINED = "undefined",
    NULL = "null",
    OBJECT = "object",
    FUNCTION = "function",
    BUFFER = "buffer",
    OTHER = "other"
}
export declare function encodeArguments(instance: any, callbacks: {
    [key: string]: Function;
}, args: any[], disabledMultithreading: boolean): ArgDefinition[];
export declare type ArgCallback = (...args: any[]) => Promise<any>;
export declare function decodeArguments(instance: () => any, args: Array<ArgDefinition>, getCallback: (arg: ArgDefinition) => ArgCallback): Array<any | ArgCallback>;
export {};
