@qping/plugin-bus 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.d.ts ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Node-side plugin SDK: fluent `createPlugin()` over the v3 named-pipe message bus.
3
+ *
4
+ * Method names map to v3 routes:
5
+ * initialize -> plugin.call.initialize
6
+ * search -> plugin.call.search
7
+ * actions -> plugin.call.invokeAction (dispatched by action id)
8
+ * handle(name) -> plugin.call.<name>
9
+ * publish -> plugin.event.<subjectId>
10
+ * hostCall -> host.call.<method>
11
+ */
12
+ import { type PluginHostEnv } from "./hostEnv.ts";
13
+ import { type ActionDefinition } from "./actions.ts";
14
+ export type { PluginHostEnv, PluginTheme } from "./hostEnv.ts";
15
+ export { HostAction, Key, Modifiers, type ActionContext, type ActionDefinition, type ActionOutcome, type DetailRequest, type HostActionKind, type HostActionRequest, type Hotkey, type HotkeyKey, type HotkeyModifiers, type LocalizedText, type RunSpec, } from "./actions.ts";
16
+ export type PluginContext = PluginHostEnv & {
17
+ action: string;
18
+ itemId: string;
19
+ query: string;
20
+ };
21
+ /** Payload of plugin.call.initialize. Host sends locale, theme, and the resolved message bag. */
22
+ export type PluginInitializeParams = PluginHostEnv & {
23
+ messages: Record<string, string>;
24
+ };
25
+ /** Payload of plugin.call.search. */
26
+ export type PluginSearchParams = PluginHostEnv & {
27
+ query: string;
28
+ mode: "global" | "plugin";
29
+ };
30
+ export type SearchIcon = {
31
+ kind: string;
32
+ value: string;
33
+ };
34
+ /**
35
+ * A search result row. Only `id`/`title`/`subtitle`/`priority`/`icon`/`actions` reach the host;
36
+ * any other field stays on the Node side and comes back as `context.item` when an action runs.
37
+ */
38
+ export type SearchItem = {
39
+ id: string;
40
+ title: string;
41
+ subtitle?: string;
42
+ priority?: number;
43
+ icon?: SearchIcon;
44
+ /** Ids of registered actions, in display order. The first one is bound to Enter. */
45
+ actions?: string[];
46
+ [extra: string]: unknown;
47
+ };
48
+ export type SearchResult = {
49
+ items: SearchItem[];
50
+ };
51
+ type PluginInitializeHandler = (params: PluginInitializeParams) => unknown | Promise<unknown>;
52
+ type PluginSearchHandler = (params: PluginSearchParams) => SearchResult | Promise<SearchResult>;
53
+ type PluginHandler = (payload: any, context: PluginContext) => unknown | Promise<unknown>;
54
+ export declare class Plugin {
55
+ #private;
56
+ initialize(handler: PluginInitializeHandler): this;
57
+ search(handler: PluginSearchHandler): this;
58
+ /**
59
+ * Registers every action this plugin offers. The list is sent to the host in the initialize
60
+ * response, so the host knows the ids, labels and hotkeys before any search runs; search items
61
+ * and the detail page then reference them by id only.
62
+ */
63
+ actions<TItem = any>(definitions: ActionDefinition<TItem>[]): this;
64
+ handle(action: string, handler: PluginHandler): this;
65
+ /** Publishes a plugin.event.<subjectId> event to all webviews in the session. */
66
+ publish(subjectId: string, payload?: unknown): void;
67
+ /** Calls a host.call.<method> capability and awaits the response.
68
+ * `timeoutMs` defaults to the remaining timeout of the inbound plugin.call
69
+ * (from a page `bus.call`) when inside a handler; otherwise 30s.
70
+ */
71
+ hostCall(method: string, params?: Record<string, unknown>, timeoutMs?: number): Promise<unknown>;
72
+ /** Connects to the host pipe and begins dispatching. Must be called last. */
73
+ start(): Promise<void>;
74
+ /**
75
+ * Builds the v3 route map from the fluent registrations. Exposed for unit testing the mapping
76
+ * without connecting a pipe.
77
+ */
78
+ buildRoutes(): Record<string, (payload: any, context?: {
79
+ sessionId: string;
80
+ }) => unknown | Promise<unknown>>;
81
+ stop(): Promise<void>;
82
+ }
83
+ export declare function createPlugin(): Plugin;