@zhin.js/plugin-runtime 1.1.20 → 1.1.21

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.
@@ -20,9 +20,11 @@ import type { JsonValue } from './persistent-state.js';
20
20
  */
21
21
  export type PluginConsoleRpcJson = JsonValue;
22
22
  export type PluginConsoleRpcInput = Readonly<Record<string, JsonValue>>;
23
- export interface PluginConsoleRpcCall {
23
+ export interface PluginConsoleRpcCall<TConfig = Record<string, unknown>> {
24
24
  /** Aborted when the Host request times out. Long work must observe it. */
25
25
  readonly signal: AbortSignal;
26
+ /** Validated plugin configuration for this generation, when available. */
27
+ readonly config?: TConfig;
26
28
  /** Authenticated operation view; no snapshot, configuration, resource or private resolver access. */
27
29
  readonly runtime?: Readonly<{
28
30
  owner: PluginId;
@@ -33,7 +35,10 @@ export interface PluginConsoleRpcCall {
33
35
  /** Framework-only request-local notification before a validated durable mutation begins. */
34
36
  commitStarted?(): void;
35
37
  }
36
- export interface PluginConsoleRpcMethod<TInput = PluginConsoleRpcInput> {
38
+ export type PluginConsoleRpcCallContext<TMethods = Record<string, unknown>, TKey extends keyof TMethods = keyof TMethods, TConfig = Record<string, unknown>> = PluginConsoleRpcCall<TConfig> & {
39
+ readonly method?: TKey;
40
+ };
41
+ export interface PluginConsoleRpcMethod<TInput = PluginConsoleRpcInput, TConfig = Record<string, unknown>> {
37
42
  /** Local name of a Page owned by the same plugin (`pages/<page>/index.tsx`). Its access rules apply. */
38
43
  readonly page?: string;
39
44
  /** Extra permissions on top of the page's own requirements. */
@@ -49,26 +54,29 @@ export interface PluginConsoleRpcMethod<TInput = PluginConsoleRpcInput> {
49
54
  * Return a small, user-facing JSON shape. Never return raw log records, prompts, chat lines,
50
55
  * secrets or exception text: the Console shows this to ordinary users.
51
56
  */
52
- handler(input: TInput, call: PluginConsoleRpcCall): JsonValue | Promise<JsonValue>;
57
+ handler(input: TInput, call: PluginConsoleRpcCall<TConfig>): JsonValue | Promise<JsonValue>;
53
58
  }
54
- export interface PluginConsoleRpcStatus extends PluginConsoleRpcMethod<PluginConsoleRpcInput> {
59
+ export interface PluginConsoleRpcStatus<TConfig = Record<string, unknown>> extends PluginConsoleRpcMethod<PluginConsoleRpcInput, TConfig> {
55
60
  /** Allow the demo-scope Console token to read this status. Default `false`. */
56
61
  readonly demo?: boolean;
57
62
  }
58
- export interface PluginConsoleRpcDefinition {
63
+ export interface PluginConsoleRpcDefinition<TConfig = Record<string, unknown>> {
59
64
  /** Read-only status for the plugin's Console page(s): `plugin.<pluginId>.status`. */
60
- readonly status?: PluginConsoleRpcStatus;
65
+ readonly status?: PluginConsoleRpcStatus<TConfig>;
61
66
  /**
62
67
  * Extra read-only views beside `status`: `plugin.<pluginId>.<name>`. Same access rules as
63
68
  * `status`; use them when one plugin backs several pages with different permissions.
64
69
  */
65
- readonly queries?: Readonly<Record<string, PluginConsoleRpcStatus>>;
70
+ readonly queries?: Readonly<Record<string, PluginConsoleRpcStatus<TConfig>>>;
66
71
  /**
67
72
  * Limited, named actions: `plugin.<pluginId>.<name>`. Non-admin tokens may run one only when the
68
73
  * action declares its own requirements and the token holds them (plus the page's); otherwise
69
74
  * admin-only.
70
75
  */
71
- readonly actions?: Readonly<Record<string, PluginConsoleRpcMethod>>;
76
+ readonly actions?: Readonly<Record<string, PluginConsoleRpcMethod<PluginConsoleRpcInput, TConfig>>>;
77
+ }
78
+ export interface PluginConsoleRpcDefiner<TConfig = Record<string, unknown>> {
79
+ (definition: PluginConsoleRpcDefinition<TConfig>): PluginConsoleRpc;
72
80
  }
73
81
  export interface NormalizedPluginConsoleRpcMethod {
74
82
  readonly page?: string;
@@ -93,4 +101,7 @@ export declare class PluginConsoleRpcError extends Error {
93
101
  export declare const pluginConsoleRpcToken: import("./token.js").Token<PluginConsoleRpc>;
94
102
  export declare const PLUGIN_CONSOLE_RPC_STATUS = "status";
95
103
  /** Validates and freezes a plugin's Console RPC surface. Throws on invalid names at setup time. */
96
- export declare function definePluginConsoleRpc(definition: PluginConsoleRpcDefinition): PluginConsoleRpc;
104
+ export declare function definePluginConsoleRpc<TConfig = Record<string, unknown>>(definition: PluginConsoleRpcDefinition<TConfig>): PluginConsoleRpc;
105
+ export declare namespace definePluginConsoleRpc {
106
+ var withConfig: <TConfig = Record<string, unknown>>() => PluginConsoleRpcDefiner<TConfig>;
107
+ }
@@ -42,6 +42,13 @@ export function definePluginConsoleRpc(definition) {
42
42
  get [generationAdmissionSource]() { return gates; },
43
43
  });
44
44
  }
45
+ /**
46
+ * Fix the plugin config type first, then define the Console RPC surface:
47
+ * `definePluginConsoleRpc.withConfig<MyConfig>()({ status: { handler(_input, call) { ... } } })`
48
+ */
49
+ definePluginConsoleRpc.withConfig = function withConfig() {
50
+ return (definition) => definePluginConsoleRpc(definition);
51
+ };
45
52
  function normalizeMethod(name, method, demo, readOnly) {
46
53
  if (!method || typeof method.handler !== 'function') {
47
54
  throw new TypeError(`Plugin Console RPC ${name} must have a handler`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/plugin-runtime",
3
- "version": "1.1.20",
3
+ "version": "1.1.21",
4
4
  "description": "Zero-dependency Plugin tree, Scope and atomic generation runtime for Zhin",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",