import * as Fiber from "./Fiber.js"; import * as Message from "./Message.js"; import * as Observable from "./Observable/index.js"; export { ClientAgent as t }; type Input = Observable.t | Message.SetValue>; type Output = Required>>; /** * Encapsulates the responsibilities of a client in order to fulfill the * transporter protocol. * * A client uses a proxy to interface with a remote resource. When a function is * called, using the proxy, a message is sent to the server to call the function. * A promise is returned while the client waits for the server to respond * with either a value or an error. */ export declare class ClientAgent extends Fiber.t { #private; private readonly decode; private readonly encode; private readonly input; private readonly noReply; private readonly output; readonly serverAddress: string; constructor(decode: (value: unknown) => unknown, encode: (value: unknown) => unknown, input: Input, noReply: boolean, output: Output, serverAddress: string); /** * Creates a `Proxy` object for a remote resource. This creates the illusion * that the resource is local, allowing familiar procedural programming to be * used to interface with the remote resource. However, because the resource * is in fact remote, all function calls will return a promise. * * For a proxied object it is possible to dereference a value at an arbitrary * path within the object. Transporter guarantees these child proxies are * referentially stable, as you would expect if you dereferenced a value in an * ordinary object. * * @example * * ``` * type User = { * id: string; * name: string; * }; * * // Our API exposes a `User` module with functions for accessing user data. * type Api = { * User: { * get(id: string): User; * list(limit?: number): User[] * } * }; * * const session = Session.client({ * protocol: JsonProtocol, * serverAddress: "api@v1" * }); * * // The `User` module can be dereferenced from the proxy. * const { User } = session.createProxy(); * * // We can now call functions directly using the proxy. Because the * // functions are actually remote we get a Promise. * const user = await User.get("User:abc"); * const users = await User.list(10); *``` * * Because Transporter guarantees proxies are referentially stable you can * reliably use memoization to cache the output of a function. * * @example * * ``` * const cache = Cache.init(); * const getUser = cache.memo(User.get); * // The output will be cached. Calling `getUser` again with the same * // arguments will return the stored value from the cache. * const user = getUser("User:abc"); *``` * * In addition, it is possible to get metadata about a proxy using the * Metadata API. * * @example * * ``` * const metadata = Metadata.get(User.get)); * * assert.equal(metadata, { * address: "api@v1", * objectPath: ["User", "get"] * }); * ``` */ createProxy(path?: string[]): () => void; } export interface Options { decode(value: unknown): unknown; encode(value: unknown): unknown; input: Input; noReply: boolean; output: Output; serverAddress: string; } /** * Creates a new `ClientAgent`. */ export declare function init({ decode, encode, input, noReply, output, serverAddress }: Options): ClientAgent; //# sourceMappingURL=ClientAgent.d.ts.map