import type { SynclinkTask } from "./task"; export declare const createEndpoint: unique symbol; export declare const releaseProxy: unique symbol; export declare const proxyMarker: unique symbol; /** * Interface of values that were marked to be proxied with `synclink.proxy()`. * Can also be implemented by classes. */ export interface ProxyMarked { [proxyMarker]: true; } /** * Takes a type that may be Promise and unwraps the Promise type. * If `P` is not a Promise, it returns `P`. * * This is the inverse of `Promisify`. */ declare type Unpromisify

= P extends Promise ? T : P; /** * Takes the raw type of a remote property and returns the type that is visible to the local thread on the proxy. * * Note: This needs to be its own type alias, otherwise it will not distribute over unions. * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types */ declare type RemoteProperty = T extends Function | ProxyMarked ? Remote : SynclinkTask; /** * Takes the raw type of a property as a remote thread would see it through a proxy (e.g. when passed in as a function * argument) and returns the type that the local thread has to supply. * * This is the inverse of `RemoteProperty`. * * Note: This needs to be its own type alias, otherwise it will not distribute over unions. See * https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types */ declare type LocalProperty = T extends Function | ProxyMarked ? Local : UnTask; /** * Proxies `T` if it is a `ProxyMarked`, clones it otherwise (as handled by structured cloning and transfer handlers). */ export declare type ProxyOrClone = T extends ProxyMarked ? Remote : T; /** * Inverse of `ProxyOrClone`. */ export declare type UnproxyOrClone = T extends RemoteObject ? Local : T; /** * Takes the raw type of a remote object in the other thread and returns the type as it is visible to the local thread * when proxied with `Synclink.proxy()`. * * This does not handle call signatures, which is handled by the more general `Remote` type. * * @template T The raw type of a remote object as seen in the other thread. */ export declare type RemoteObject = { [P in keyof T]: RemoteProperty; }; /** * Takes the type of an object as a remote thread would see it through a proxy (e.g. when passed in as a function * argument) and returns the type that the local thread has to supply. * * This does not handle call signatures, which is handled by the more general `Local` type. * * This is the inverse of `RemoteObject`. * * @template T The type of a proxied object. */ export declare type LocalObject = { [P in keyof T]: LocalProperty; }; /** * Additional special synclink methods available on each proxy returned by `Synclink.wrap()`. */ export interface ProxyMethods { [createEndpoint]: () => Promise; [releaseProxy]: () => SynclinkTask; } declare type UnTask = T extends SynclinkTask ? S : T; declare type MaybePromise = Promise | T; /** * Takes the raw type of a remote object, function or class in the other thread and returns the type as it is visible to * the local thread from the proxy return value of `Synclink.wrap()` or `Synclink.proxy()`. */ export declare type Remote = RemoteObject & (T extends (...args: infer TArguments) => infer TReturn ? (...args: { [I in keyof TArguments]: UnproxyOrClone; }) => SynclinkTask>> : unknown) & (T extends { new (...args: infer TArguments): infer TInstance; } ? { new (...args: { [I in keyof TArguments]: UnproxyOrClone; }): SynclinkTask>; } : unknown) & ProxyMethods; /** * Takes the raw type of a remote object, function or class as a remote thread would see it through a proxy (e.g. when * passed in as a function argument) and returns the type the local thread has to supply. * * This is the inverse of `Remote`. It takes a `Remote` and returns its original input `T`. */ export declare type Local = Omit, keyof ProxyMethods> & (T extends (...args: infer TArguments) => infer TReturn ? (...args: { [I in keyof TArguments]: ProxyOrClone; }) => MaybePromise>> : unknown) & (T extends { new (...args: infer TArguments): infer TInstance; } ? { new (...args: { [I in keyof TArguments]: ProxyOrClone; }): MaybePromise>>; } : unknown); export {};