import type { Emits, GuestConnection, GuestConnectionEvents, GuestApis, CrossRealmObject, VirtualApi, GuestMetadata } from "@adobe/uix-core"; import { Emitter } from "@adobe/uix-core"; /** * A specifier for methods to be expected on a remote interface. * * @remarks * A CapabilitySpec is a description of an interface, like a very simplified * type definition. It specifies an object structure and the paths in that * structure that must be functions. (It doesn't specify anything about the * signatures or return values of those functions.) * * Use CapabilitySpec objects as queries, or filters, to get a subset of * installed extensions which have registered methods which match the spec. * * @example * As an extensible app developer, you are making an extension point for spell * check. Your code expects extensions to register an API `spellCheck` with * methods called `spellCheck.correct(text)` and `spellCheck.suggest(text)`. * * ```javascript * async function correctText(text) { * const spellCheckers = host.getLoadedGuests({ * spellCheck: [ * 'correct', * 'suggest' * ] * }); * let correcting = text; * for (const checker of spellCheckers) { * correcting = await checker.apis.spellCheck.correct(correcting); * } * return Promise.all(checkers.map(checker => * checker.apis.spellCheck.suggest(correcting) * )); * } * ``` * * @public */ export type CapabilitySpec = { [Name in keyof T]+?: (keyof T[Name])[]; }; /** @public */ export type PortOptions = { /** * Time in milliseconds to wait for the guest to connect before throwing. */ timeout?: number; /** * Set true to log copiously in the console. */ debug?: boolean; }; /** * A Port is the Host-maintained object representing an extension running as a * guest. It exposes methods registered by the Guest, and can provide Host * methods back to the guest. * * @remarks * When the Host object loads extensions via {@link Host.load}, it creates a * Port object for each extension. When retrieving and filtering extensions * via {@link Host.(getLoadedGuests:2)}, a list of Port objects is returned. From * the point of view of the extensible app using the Host object, extensions * are always Port objects, which expose the methods registered by the * extension at the {@link Port.apis} property. * * @privateRemarks * We've gone through several possible names for this object. GuestProxy, * GuestInterface, GuestConnection, etc. "Port" is not ideal, but it conflicted * the least with other types we defined in early drafts. It's definitely * something we should review. * @public */ export declare class Port extends Emitter implements GuestConnection { get apis(): VirtualApi; get metadata(): GuestMetadata; private debug; private logger?; private guestServerFrame; private hostApis; private isLoaded; private isGuestReady; private guestReadyMessageHandler; private runtimeContainer; private sharedContext; private configuration?; private subscriptions; private timeout; /** * If any errors occurred during the loading of guests, this property will * contain the error that was raised. * @public */ error?: Error; /** * The URL of the guest provided by the extension registry. The Host will * load this URL in the background, in the invisible the bootstrap frame, so * this URL must point to a page that calls {@link @adobe/uix-guest#register} * when it loads. */ url: URL; extensionPoints: string[]; private guestServer; private guestVersion; constructor(config: { owner: string; id: string; url: URL; /** * An alternate DOM element to use for invisible iframes. Will create its * own if this option is not populated with a DOM element. */ runtimeContainer: HTMLElement; options: PortOptions; logger?: Console; /** * Initial object to populate the shared context with. Once the guest * connects, it will be able to access these properties. */ sharedContext: Record; /** * A guest (extension) configuration */ configuration?: Record; /** * Guest (extension) extension points */ extensionPoints?: string[]; events: Emits; }); /** * Connect an iframe element which is displaying another page in the extension * with the extension's bootstrap frame, so they can share context and events. */ attachUI(iframe: HTMLIFrameElement, privateMethods: VirtualApi): Promise>; /** * Returns true if the guest has registered methods matching the provided * capability spec. A capability spec is simply an object whose properties are * declared in an array of keys, description the names of the functions and * methods that the Port will expose. */ hasCapabilities(requiredCapabilities: CapabilitySpec): boolean; private getGuestVersion; /** * True when all extensions have loaded. */ isReady(): boolean; /** * Loads the extension. Returns a promise which resolves when the extension * has loaded. The Host calls this method after retrieving extensions. */ load(): Promise; /** * The host-side equivalent of {@link @adobe/uix-guest#register}. Pass a set * of methods down to the guest as proxies. * Merges at the first level, the API level. Overwrites a deeper levels. */ provide(apis: VirtualApi): void; /** * Disconnect from the extension. */ unload(): Promise; /** * Recursive method that wraps every function in apis object and adds * an event */ private addApiMiddleware; private hasCapability; private assert; private assertReady; private attachFrame; private connect; private getHostMethodCallee; private invokeHostMethod; } //# sourceMappingURL=port.d.ts.map