/** * Generic function type definition. * * @template Params - The types of the function parameters. * @template Return - The return type of the function. */ export type Fn = (...params: Params) => Return; /** * Recursive type representing a module structure where functions are preserved * and nested objects are treated as sub-modules. * * @template Config - The configuration object describing the module structure. */ export type Mod = { [M in keyof Config]: Config[M] extends (...args: any[]) => any ? Config[M] extends Fn ? Fn : never : Config[M] extends object ? Mod : Config[M]; }; /** * Base type for a module configuration, allowing nested string-keyed objects. */ export type ModuleConfig = Record>; /** * Configuration for creating a worker. * * @template C - The module configuration type. */ export type WorkerConfig = { /** The module implementation containing the actual functions. */ mod: Mod; }; /** * Represents the worker instance returned by `createWorker`. * * @template C - The module configuration type. */ export type MyceliumWorker = { /** The client-side configuration derived from the worker's module. */ config: ClientConfig; }; /** * Utility type to extract the client configuration type from a worker type. * * @template Worker - The worker type to infer from. */ export type InferClientConfig = Worker extends { $config: infer Config; } ? Config : never; /** * Represents the client-side view of the worker's module structure. * * @remarks * Functions are replaced with the string "function", and nested modules are * represented by a recursive structure with a "module" type and "exports". * * @template Config - The module configuration type. */ export type ClientConfig = { [M in keyof Config]: Config[M] extends (...args: any[]) => any ? "function" : { type: "module"; exports: ClientConfig; }; };