export default makeE; export type EProxy = ReturnType<(HandledPromise: HandledPromiseConstructor) => ((x: T) => ECallableOrMethods>) & { /** * E.get(x) returns a proxy on which you can get arbitrary properties. * Each of these properties returns a promise for the property. The promise * value will be the property fetched from whatever 'x' designates (or * resolves to) in a future turn, not this one. * * @template T * @param {T} x target for property get * @returns {EGetters>} property get proxy * @readonly */ readonly get: (x: T) => EGetters>; /** * E.resolve(x) converts x to a handled promise. It is * shorthand for HandledPromise.resolve(x) * * @template T * @param {T} x value to convert to a handled promise * @returns {Promise>} handled promise for x * @readonly */ readonly resolve: { (): Promise; (value: T): Promise>; (value: T | PromiseLike): Promise>; }; /** * E.sendOnly returns a proxy similar to E, but for which the results * are ignored (undefined is returned). * * @template T * @param {T} x target for method/function call * @returns {ESendOnlyCallableOrMethods>} method/function call proxy * @readonly */ readonly sendOnly: (x: T) => ESendOnlyCallableOrMethods>; /** * E.when(x, res, rej) is equivalent to * HandledPromise.resolve(x).then(res, rej) * * @template T * @template [U = T] * @param {T|PromiseLike} x value to convert to a handled promise * @param {(value: T) => ERef} [onfulfilled] * @param {(reason: any) => ERef} [onrejected] * @returns {Promise} * @readonly */ readonly when: (x: T | PromiseLike, onfulfilled?: (value: T) => ERef, onrejected?: (reason: any) => ERef) => Promise; }>; /** * Declare an object that is potentially a far reference of type Primary whose * auxilliary data has type Local. This should be used only for consumers of * Far objects in arguments and declarations; the only creators of Far objects * are distributed object creator components like the `Far` or `Remotable` * functions. */ export type FarRef> = ERef>; /** * `DataOnly` means to return a record type `T2` consisting only of * properties that are *not* functions. */ export type DataOnly = Omit>; /** * Declare that `T` may or may not be a Promise. This should be used only for * consumers of arguments and declarations; return values should specifically be * `Promise` or `T` itself. */ export type ERef = PromiseLike | T; /** * The awaited return type of a function. * For the eventual result of an E call, */ export type EReturn any> = T extends (...args: any[]) => infer R ? Awaited : never; /** * An eventual value where remotable objects are recursively mapped to Remote types */ export type EResult = Awaited; /** * Experimental type mapping remotable objects to Remote types */ export type EAwaitedResult = (0 extends (1 & T) ? T : T extends RemotableBrand ? (P | RemotableBrand) : T extends PromiseLike ? Promise>> : T extends (null | undefined | string | number | boolean | symbol | bigint | Callable) ? T : T extends object ? { [P in keyof T]: EAwaitedResult; } : T); /** * The */ export type ECallableReturn any> = (0 extends (1 & T) ? any : T extends (...args: any[]) => infer R ? EResult : never); /** * Maps a callable to its remotely called type */ export type ECallable = (ReturnType extends PromiseLike ? T : (...args: Parameters) => Promise>); export type EMethods = { readonly [P in keyof T]: T[P] extends Callable ? ECallable : never; }; export type EGetters = { readonly [P in keyof T]: T[P] extends PromiseLike ? T[P] : Promise>; }; export type ESendOnlyCallable = (...args: Parameters) => Promise; export type ESendOnlyMethods = { readonly [P in keyof T]: T[P] extends Callable ? ESendOnlyCallable : never; }; export type ESendOnlyCallableOrMethods = (0 extends (1 & T) ? any : T extends Callable ? ESendOnlyCallable & ESendOnlyMethods> : ESendOnlyMethods>); export type ECallableOrMethods = (0 extends (1 & T) ? any : T extends Callable ? ECallable & EMethods> : EMethods>); /** * Return a union of property names/symbols/numbers P for which the record element T[P]'s type extends U. * * Given const x = { a: 123, b: 'hello', c: 42, 49: () => {}, 53: 67 }, * * FilteredKeys is the type 'a' | 'c' | 53. * FilteredKeys is the type 'b'. * FilteredKeys is the type 'c' | 53. * FilteredKeys is the type never. */ export type FilteredKeys = { [P in keyof T]: T[P] extends U ? P : never; }[keyof T]; /** * `PickCallable` means to return a single root callable or a record type * consisting only of properties that are functions. */ export type PickCallable = (0 extends (1 & T) ? any : T extends Callable ? (...args: Parameters) => ReturnType : Pick>); /** * `RemoteFunctions` means to return the functions and properties that are remotely callable. */ export type RemoteFunctions = (0 extends (1 & T) ? any : T extends RemotableBrand ? PickCallable : T extends PromiseLike ? RemoteFunctions : T); export type LocalRecord = (T extends RemotableBrand ? L : T extends PromiseLike ? LocalRecord : T); export type EPromiseKit = { promise: Promise; settler: Settler; }; /** * Declare a near object that must only be invoked with E, even locally. It * supports the `T` interface but additionally permits `T`'s methods to return * `PromiseLike`s even if `T` declares them as only synchronous. */ export type EOnly = (T extends Callable ? (...args: Parameters) => ERef>>> : T extends Record ? { [K in keyof T]: T[K] extends Callable ? (...args: Parameters) => ERef>>> : T[K]; } : T); /** * @param {HandledPromiseConstructor} HandledPromise */ declare function makeE(HandledPromise: HandledPromiseConstructor): ((x: T) => ECallableOrMethods>) & { /** * E.get(x) returns a proxy on which you can get arbitrary properties. * Each of these properties returns a promise for the property. The promise * value will be the property fetched from whatever 'x' designates (or * resolves to) in a future turn, not this one. * * @template T * @param {T} x target for property get * @returns {EGetters>} property get proxy * @readonly */ readonly get: (x: T) => EGetters>; /** * E.resolve(x) converts x to a handled promise. It is * shorthand for HandledPromise.resolve(x) * * @template T * @param {T} x value to convert to a handled promise * @returns {Promise>} handled promise for x * @readonly */ readonly resolve: { (): Promise; (value: T): Promise>; (value: T | PromiseLike): Promise>; }; /** * E.sendOnly returns a proxy similar to E, but for which the results * are ignored (undefined is returned). * * @template T * @param {T} x target for method/function call * @returns {ESendOnlyCallableOrMethods>} method/function call proxy * @readonly */ readonly sendOnly: (x: T) => ESendOnlyCallableOrMethods>; /** * E.when(x, res, rej) is equivalent to * HandledPromise.resolve(x).then(res, rej) * * @template T * @template [U = T] * @param {T|PromiseLike} x value to convert to a handled promise * @param {(value: T) => ERef} [onfulfilled] * @param {(reason: any) => ERef} [onrejected] * @returns {Promise} * @readonly */ readonly when: (x: T | PromiseLike, onfulfilled?: (value: T) => ERef, onrejected?: (reason: any) => ERef) => Promise; }; import type { HandledPromiseConstructor } from './types.js'; import type { RemotableBrand } from './types.js'; import type { Callable } from './types.js'; import type { Settler } from './types.js'; //# sourceMappingURL=E.d.ts.map