@nan0web/ui 1.0.3 → 1.0.4

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.
Files changed (41) hide show
  1. package/README.md +18 -20
  2. package/package.json +15 -16
  3. package/src/App/Core/UI.js +0 -46
  4. package/src/App/Core/Widget.js +4 -6
  5. package/src/App/User/Command/Message.js +23 -37
  6. package/src/App/User/Command/index.js +3 -8
  7. package/src/App/User/UserApp.js +30 -10
  8. package/src/README.md.js +33 -33
  9. package/src/StdIn.js +12 -13
  10. package/src/View/View.js +5 -5
  11. package/src/core/Form/Form.js +8 -6
  12. package/src/core/Form/Input.js +1 -1
  13. package/src/core/Form/Message.js +6 -5
  14. package/src/core/InputAdapter.js +2 -2
  15. package/src/core/Message/Message.js +109 -19
  16. package/src/core/Message/OutputMessage.js +7 -7
  17. package/src/core/Message/index.js +3 -4
  18. package/src/core/Stream.js +10 -10
  19. package/src/core/UiAdapter.js +189 -0
  20. package/src/core/index.js +3 -6
  21. package/src/index.js +4 -4
  22. package/types/App/Core/UI.d.ts +0 -10
  23. package/types/App/Core/Widget.d.ts +6 -7
  24. package/types/App/User/Command/Message.d.ts +15 -28
  25. package/types/App/User/Command/index.d.ts +3 -4
  26. package/types/App/User/UserApp.d.ts +14 -7
  27. package/types/StdIn.d.ts +13 -13
  28. package/types/View/View.d.ts +6 -6
  29. package/types/core/Form/Form.d.ts +2 -5
  30. package/types/core/Form/Input.d.ts +1 -1
  31. package/types/core/Form/Message.d.ts +5 -10
  32. package/types/core/Intent.d.ts +91 -0
  33. package/types/core/Message/Message.d.ts +58 -15
  34. package/types/core/Message/OutputMessage.d.ts +3 -3
  35. package/types/core/Message/index.d.ts +3 -4
  36. package/types/core/Stream.d.ts +5 -4
  37. package/types/core/UiAdapter.d.ts +104 -0
  38. package/types/core/index.d.ts +2 -3
  39. package/types/index.d.ts +4 -4
  40. package/src/App/User/Command/Options.js +0 -48
  41. package/src/core/Message/InputMessage.js +0 -119
@@ -1,29 +1,16 @@
1
- export default UserAppCommandMessage;
2
- /**
3
- * Extends Command.Message to include user-specific command options.
4
- */
5
- declare class UserAppCommandMessage {
6
- /**
7
- * Parses an array of strings into a UserAppCommandMessage.
8
- * @param {string[] | string} value - Arguments to parse
9
- * @returns {UserAppCommandMessage} Parsed command message
10
- */
11
- static parse(value?: string[] | string): UserAppCommandMessage;
12
- /**
13
- * Creates a new UserAppCommandMessage instance.
14
- * @param {object} props - Command message properties
15
- * @param {string[]} [props.args=[]] - Command arguments
16
- * @param {Partial<UserAppCommandOptions>} [props.opts={}] - User-specific options
17
- */
18
- constructor(props?: {
19
- args?: string[] | undefined;
20
- opts?: Partial<UserAppCommandOptions> | undefined;
21
- });
22
- /**
23
- * @param {Partial<UserAppCommandOptions>} value
24
- */
25
- set opts(value: Partial<UserAppCommandOptions>);
26
- /** @returns {UserAppCommandOptions} */
27
- get opts(): UserAppCommandOptions;
1
+ export class DepsCommand extends UIMessage {
2
+ static Body: typeof DepsCommandParams;
3
+ constructor(input?: {});
4
+ /** @type {DepsCommandParams} */
5
+ body: DepsCommandParams;
6
+ }
7
+ export default DepsCommand;
8
+ import UIMessage from "../../../core/Message/Message.js";
9
+ declare class DepsCommandParams {
10
+ static fix: {
11
+ help: string;
12
+ defaultValue: boolean;
13
+ };
14
+ constructor(input?: {});
15
+ fix: boolean;
28
16
  }
29
- import UserAppCommandOptions from "./Options.js";
@@ -1,5 +1,4 @@
1
- declare const _default: any;
2
- export default _default;
1
+ export default CommandMessage;
3
2
  import CommandMessage from "./Message.js";
4
- import CommandOptions from "./Options.js";
5
- export { CommandMessage, CommandOptions };
3
+ import DepsCommand from "./Message.js";
4
+ export { CommandMessage, DepsCommand };
@@ -1,34 +1,41 @@
1
- export default UserApp;
2
1
  /**
3
2
  * UserApp requires user name and shows Welcome view.
4
3
  * If user.name is provided in command input, ignores user input.
5
4
  * User can change user data to see another Welcome view.
6
5
  */
7
- declare class UserApp extends CoreApp {
6
+ export default class UserApp extends CoreApp {
8
7
  /**
9
8
  * Creates a new UserApp instance.
10
9
  * @param {Partial<CoreApp>} [props={}] - UserApp properties
11
10
  */
12
11
  constructor(props?: Partial<CoreApp>);
12
+ /**
13
+ * Handle deps command with async generator for stream processing.
14
+ * @param {DepsCommand} cmd - Command message with deps parameters
15
+ * @param {UserUI} ui - UI instance
16
+ * @returns {Promise<Object>} Command output
17
+ */
18
+ handleDeps(cmd: DepsCommand, ui: UserUI): Promise<any>;
13
19
  /**
14
20
  * Set user data from params.
15
- * @param {Message} cmd - Command message with user data
21
+ * @param {UserAppCommandMessage} cmd - Command message with user data
16
22
  * @param {UserUI} ui - UI instance
17
23
  * @returns {Promise<{ message: string }>} Welcome message
18
24
  */
19
- setUser(cmd: Message, ui: UserUI): Promise<{
25
+ setUser(cmd: UserAppCommandMessage, ui: UserUI): Promise<{
20
26
  message: string;
21
27
  }>;
22
28
  /**
23
29
  * Show welcome message for current user.
24
- * @param {Message} cmd - Command message
30
+ * @param {UserAppCommandMessage} cmd - Command message
25
31
  * @param {UserUI} ui - UI instance
26
32
  * @returns {Promise<string[][]>} Welcome view output
27
33
  */
28
- welcome(cmd: Message, ui: UserUI): Promise<string[][]>;
34
+ welcome(cmd: UserAppCommandMessage, ui: UserUI): Promise<string[][]>;
29
35
  user: User | undefined;
30
36
  }
31
37
  import CoreApp from "../Core/CoreApp.js";
32
- import { Message } from "@nan0web/co";
38
+ import DepsCommand from "./Command/Message.js";
33
39
  import UserUI from "./UserUI.js";
40
+ import UserAppCommandMessage from "./Command/Message.js";
34
41
  import User from "../../Model/User/User.js";
package/types/StdIn.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- export default StdIn;
2
1
  /**
3
2
  * Handles standard input stream with message buffering.
4
3
  */
5
- declare class StdIn extends EventProcessor {
4
+ export default class StdIn extends EventProcessor {
6
5
  /** @type {number} Read interval in milliseconds */
7
6
  static READ_INTERVAL: number;
8
7
  /** @type {string[]} Messages to ignore */
@@ -17,14 +16,14 @@ declare class StdIn extends EventProcessor {
17
16
  * Creates a new StdIn instance.
18
17
  * @param {object} props - StdIn properties
19
18
  * @param {Processor} [props.processor] - Input processor
20
- * @param {InputMessage[]} [props.stream=[]] - Initial input stream
19
+ * @param {UiMessage[]} [props.stream=[]] - Initial input stream
21
20
  */
22
21
  constructor(props?: {
23
22
  processor?: Processor | undefined;
24
- stream?: InputMessage[] | undefined;
23
+ stream?: UiMessage[] | undefined;
25
24
  });
26
- /** @type {InputMessage[]} Input message buffer */
27
- stream: InputMessage[];
25
+ /** @type {UiMessage[]} Input message buffer */
26
+ stream: UiMessage[];
28
27
  /** @type {Processor} Input processor */
29
28
  processor: Processor;
30
29
  /**
@@ -40,9 +39,9 @@ declare class StdIn extends EventProcessor {
40
39
  /**
41
40
  * Reads a message from the input stream.
42
41
  * Waits until messages are available if stream is empty.
43
- * @returns {Promise<InputMessage>} Next input message
42
+ * @returns {Promise<UiMessage>} Next input message
44
43
  */
45
- read(): Promise<InputMessage>;
44
+ read(): Promise<UiMessage>;
46
45
  /**
47
46
  * Writes a message to the input stream.
48
47
  * @param {string} message - Message to write
@@ -50,13 +49,14 @@ declare class StdIn extends EventProcessor {
50
49
  */
51
50
  write(message: string): boolean;
52
51
  /**
53
- * Decodes a message into an InputMessage instance.
54
- * @param {InputMessage | string[] | any} message - Message to decode
55
- * @returns {InputMessage} Decoded input message
52
+ * Decodes a message into an UiMessage instance.
53
+ * @param {UiMessage | string[] | any} message - Message to decode
54
+ * @returns {UiMessage} Decoded input message
56
55
  */
57
- decode(message: InputMessage | string[] | any): InputMessage;
56
+ decode(message: UiMessage | string[] | any): UiMessage;
58
57
  }
59
58
  import EventProcessor from "@nan0web/event/oop";
60
- import InputMessage from "./core/Message/InputMessage.js";
59
+ import { UiMessage } from "./core/index.js";
61
60
  declare class Processor extends EventProcessor {
62
61
  }
62
+ export {};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @typedef {Object} ComponentFn
3
3
  * @property {string} name
4
- * @property {(input: InputMessage) => Promise<any>} ask
4
+ * @property {(input: UiMessage) => Promise<any>} ask
5
5
  * @property {Function} bind
6
6
  */
7
7
  export default class View {
@@ -96,14 +96,14 @@ export default class View {
96
96
  */
97
97
  get(name: string): ComponentFn | undefined;
98
98
  /**
99
- * @param {InputMessage} input
100
- * @returns {Promise<InputMessage | null>}
99
+ * @param {UiMessage} input
100
+ * @returns {Promise<UiMessage | null>}
101
101
  */
102
- ask(input: InputMessage): Promise<InputMessage | null>;
102
+ ask(input: UiMessage): Promise<UiMessage | null>;
103
103
  }
104
104
  export type ComponentFn = {
105
105
  name: string;
106
- ask: (input: InputMessage) => Promise<any>;
106
+ ask: (input: UiMessage) => Promise<any>;
107
107
  bind: Function;
108
108
  };
109
109
  import StdIn from "../StdIn.js";
@@ -112,4 +112,4 @@ import Frame from "../Frame/Frame.js";
112
112
  import Locale from "../Locale.js";
113
113
  import { FrameRenderMethod } from "../Frame/Frame.js";
114
114
  import RenderOptions from "./RenderOptions.js";
115
- import InputMessage from "../core/Message/InputMessage.js";
115
+ import UiMessage from "../core/Message/Message.js";
@@ -89,12 +89,9 @@ export default class UIForm extends FormMessage {
89
89
  /**
90
90
  * Validates the entire form.
91
91
  *
92
- * @returns {{isValid: boolean, errors: Object}} Validation result.
92
+ * @returns {Map<string, string>} Map of validation errors, empty if valid.
93
93
  */
94
- validate(): {
95
- isValid: boolean;
96
- errors: any;
97
- };
94
+ validate(): Map<string, string>;
98
95
  /**
99
96
  * Validates a single field.
100
97
  *
@@ -64,7 +64,7 @@ export default class FormInput {
64
64
  /** @type {boolean} */ required: boolean;
65
65
  /** @type {string} */ placeholder: string;
66
66
  /** @type {InputOptions} */ options: InputOptions;
67
- /** @type {Function|null} */ validation: Function | null;
67
+ /** @type {import("@nan0web/co").ValidateFn|null} */ validation: import("@nan0web/co").ValidateFn | null;
68
68
  /** @type {*} */ defaultValue: any;
69
69
  requireValidType(): void;
70
70
  /**
@@ -1,16 +1,11 @@
1
1
  /**
2
- * FormMessage – specialized InputMessage for forms.
2
+ * FormMessage – specialized UiMessage for forms.
3
+ * It carries form-specific data and schema for validation.
3
4
  *
4
5
  * @class FormMessage
5
- * @extends InputMessage
6
+ * @extends UiMessage
6
7
  */
7
- export default class FormMessage extends InputMessage {
8
- /**
9
- * Creates a FormMessage.
10
- *
11
- * @param {Object} [input={}] - Message properties.
12
- */
13
- constructor(input?: any);
8
+ export default class FormMessage extends UiMessage {
14
9
  data: any;
15
10
  schema: any;
16
11
  /**
@@ -31,4 +26,4 @@ export default class FormMessage extends InputMessage {
31
26
  errors: any;
32
27
  };
33
28
  }
34
- import InputMessage from "../Message/InputMessage.js";
29
+ import UiMessage from "../Message/Message.js";
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Intent represents the user's declared will to perform an action.
3
+ * It is interface-agnostic and can be validated or executed without
4
+ * any UI, CLI, or external dependencies.
5
+ *
6
+ * An Intent may be:
7
+ * - Ready: all required data is valid → can be executed immediately
8
+ * - Partial: some data missing or invalid → requires user action
9
+ * - Invalid: cannot be fulfilled under any interface (e.g., restricted field)
10
+ *
11
+ * @example
12
+ * const intent = new Intent({
13
+ * target: LoginMessage,
14
+ * body: { username: "alice" }
15
+ * })
16
+ * if (!intent.isReady()) {
17
+ * const validMsg = await handleIntent(intent, adapter)
18
+ * }
19
+ */
20
+ declare class Intent extends Message {
21
+ /**
22
+ * Create a new Intent.
23
+ *
24
+ * @param {object} input
25
+ * @param {typeof Message} input.target - message class this intent wants to create
26
+ * @param {any} [input.context] - execution context
27
+ * @param {object} [body] - partial or complete data for the target message
28
+ */
29
+ constructor({ target, context, ...body }?: {
30
+ target: typeof Message;
31
+ context?: any;
32
+ });
33
+ /**
34
+ * The target Message class this Intent aims to produce.
35
+ * Must be a class with a static `.Body` schema.
36
+ *
37
+ * @type {typeof Message | null}
38
+ */
39
+ target: typeof Message | null;
40
+ /**
41
+ * Optional context for execution (session, locale, state, etc.).
42
+ *
43
+ * @type {any}
44
+ */
45
+ context: any;
46
+ /**
47
+ * Validates all fields in the Intent's body against the target's schema.
48
+ *
49
+ * Checks:
50
+ * - Required fields presence and non-emptiness
51
+ * - Pattern matching (RegExp)
52
+ * - Value within allowed options (if defined)
53
+ * - Custom validation logic (if `validate` function is defined)
54
+ *
55
+ * @returns {Map<string, string>} Map of field → error message, empty if valid
56
+ */
57
+ validateIntent(): Map<string, string>;
58
+ /**
59
+ * Executes the Intent by creating a valid instance of the target message.
60
+ *
61
+ * If the Intent is not ready (has validation errors), returns null.
62
+ *
63
+ * @returns {Message | null} the created message, or null if invalid
64
+ */
65
+ execute(): Message | null;
66
+ /**
67
+ * Checks if the Intent can be executed immediately, without user input.
68
+ *
69
+ * @returns {boolean} true if all required fields are valid
70
+ */
71
+ isReady(): boolean;
72
+ /**
73
+ * Converts the Intent to a plain object for logging or inspection.
74
+ *
75
+ * @returns {object} serializable object with intent, body, and context
76
+ */
77
+ toObject(): object;
78
+ }
79
+ declare namespace Intent {
80
+ /**
81
+ * Handles an Intent by fulfilling missing or invalid fields.
82
+ *
83
+ * @param {Intent} intent - the declared intent to handle
84
+ * @param {object} inputAdapter - must have `.ask(prompt)`
85
+ * @returns {Promise<Message | null>} resolved when intent is fulfilled
86
+ * @throws {CancelError} if user cancels
87
+ */
88
+ function handleIntent(intent: Intent, inputAdapter: object): Promise<Message | null>;
89
+ }
90
+ export default Intent;
91
+ import { Message } from "@nan0web/co";
@@ -1,11 +1,33 @@
1
- export default UIMessage;
2
1
  /**
3
- * Base UI message class.
2
+ * @typedef {Object} MessageBodySchema
3
+ * @property {boolean} [required]
4
+ * @property {string} [help]
5
+ * @property {RegExp} [pattern]
6
+ * @property {string[]} [options]
7
+ * @property {*} [defaultValue]
8
+ * @property {Function} [validate]
9
+ */
10
+ /**
11
+ * Base message class for UI communications.
12
+ * A message holds structured data (body) defined by a static Body class.
13
+ * It can represent commands, forms, alerts, or any UI unit.
14
+ *
15
+ * @class UiMessage
16
+ * @extends Message
4
17
  *
5
- * @class UIMessage
6
- * @extends BaseMessage
18
+ * @example
19
+ * class UserLoginMessage extends UiMessage {
20
+ * static Body = class {
21
+ * static username = { required: true, help: "Enter username" }
22
+ * static password = { required: true, type: "password" }
23
+ * constructor({ username = "", password = "" }) {
24
+ * this.username = username
25
+ * this.password = password
26
+ * }
27
+ * }
28
+ * }
7
29
  */
8
- declare class UIMessage extends BaseMessage {
30
+ export default class UiMessage extends Message {
9
31
  static TYPES: {
10
32
  TEXT: string;
11
33
  FORM: string;
@@ -18,14 +40,22 @@ declare class UIMessage extends BaseMessage {
18
40
  NAVIGATION: string;
19
41
  };
20
42
  /**
21
- * Creates a UIMessage instance from plain data.
43
+ * Creates a UiMessage instance from plain data.
22
44
  *
23
45
  * @param {Object} data - Message data.
24
- * @returns {UIMessage}
46
+ * @returns {UiMessage}
47
+ */
48
+ static from(data: any): UiMessage;
49
+ /**
50
+ * Initializes body from input using static Body schema.
51
+ *
52
+ * @param {Object} input - Input object.
53
+ * @param {Function} BodyClass - Static body class with defaults and schema.
54
+ * @returns {Object} Parsed body.
25
55
  */
26
- static from(data: any): UIMessage;
56
+ static parseBody(input: any, BodyClass: Function): any;
27
57
  /**
28
- * Creates a UIMessage.
58
+ * Creates a UiMessage.
29
59
  *
30
60
  * @param {Object} [input={}] - Message properties.
31
61
  */
@@ -35,16 +65,29 @@ declare class UIMessage extends BaseMessage {
35
65
  /** @type {string} */
36
66
  id: string;
37
67
  /**
38
- * Checks if the message type is valid.
68
+ * Validates the message body against its schema.
39
69
  *
40
- * @returns {boolean}
70
+ * NOTE: The signature must exactly match `Message.validate` – it returns a
71
+ * `Map<string,string>` regardless of the generic type, otherwise TypeScript
72
+ * reports incompatibility with the base class.
73
+ *
74
+ * @param {any} [body=this.body] - Optional body to validate.
75
+ * @returns {Map<string,string>} Map of validation errors, empty if valid.
41
76
  */
42
- isValidType(): boolean;
77
+ validate(body?: any): Map<string, string>;
43
78
  /**
44
- * Checks whether the message contains any body content.
79
+ * Checks if the message type is valid.
45
80
  *
46
81
  * @returns {boolean}
47
82
  */
48
- isEmpty(): boolean;
83
+ isValidType(): boolean;
49
84
  }
50
- import { Message as BaseMessage } from "@nan0web/co";
85
+ export type MessageBodySchema = {
86
+ required?: boolean | undefined;
87
+ help?: string | undefined;
88
+ pattern?: RegExp | undefined;
89
+ options?: string[] | undefined;
90
+ defaultValue?: any;
91
+ validate?: Function | undefined;
92
+ };
93
+ import { Message } from "@nan0web/co";
@@ -2,9 +2,9 @@
2
2
  * OutputMessage – message sent from the system to the UI.
3
3
  *
4
4
  * @class OutputMessage
5
- * @extends UIMessage
5
+ * @extends UiMessage
6
6
  */
7
- export default class OutputMessage extends UIMessage {
7
+ export default class OutputMessage extends UiMessage {
8
8
  static PRIORITY: {
9
9
  LOW: number;
10
10
  NORMAL: number;
@@ -50,4 +50,4 @@ export default class OutputMessage extends UIMessage {
50
50
  */
51
51
  toJSON(): any;
52
52
  }
53
- import UIMessage from "./Message.js";
53
+ import UiMessage from "./Message.js";
@@ -1,5 +1,4 @@
1
- export default UIMessage;
2
- import UIMessage from "./Message.js";
3
- import InputMessage from "./InputMessage.js";
1
+ export default UiMessage;
2
+ import UiMessage from "./Message.js";
4
3
  import OutputMessage from "./OutputMessage.js";
5
- export { UIMessage, InputMessage, OutputMessage };
4
+ export { UiMessage, OutputMessage };
@@ -1,5 +1,6 @@
1
+ export { StreamEntry };
1
2
  /**
2
- * Agnostic UI stream for processing progress.
3
+ * Agnostic UI stream for processing progress using async generators.
3
4
  *
4
5
  * @class UIStream
5
6
  */
@@ -13,15 +14,15 @@ export default class UIStream {
13
14
  */
14
15
  static createProcessor(signal: AbortSignal, processorFn: () => Promise<StreamEntry>): () => AsyncGenerator<StreamEntry>;
15
16
  /**
16
- * Runs a generator with progress callbacks and abort handling.
17
+ * Runs an async generator with progress callbacks and abort handling.
17
18
  *
18
19
  * @param {AbortSignal} signal - Abort signal.
19
- * @param {Function} generator - Function returning an async iterator.
20
+ * @param {() => AsyncGenerator<StreamEntry>} generatorFn - Function that returns an async generator.
20
21
  * @param {Function} [onProgress] - Called with (progress, item).
21
22
  * @param {Function} [onError] - Called with (errorMessage, item).
22
23
  * @param {Function} [onComplete] - Called with (item) when done.
23
24
  * @returns {Promise<void>}
24
25
  */
25
- static process(signal: AbortSignal, generator: Function, onProgress?: Function, onError?: Function, onComplete?: Function): Promise<void>;
26
+ static process(signal: AbortSignal, generatorFn: () => AsyncGenerator<StreamEntry>, onProgress?: Function, onError?: Function, onComplete?: Function): Promise<void>;
26
27
  }
27
28
  import StreamEntry from "./StreamEntry.js";
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Generates a UIForm from a static Body schema.
3
+ *
4
+ * @param {Function} BodyClass - Class defining field schema.
5
+ * @param {Object} [options={}] - Generation options.
6
+ * @param {Object} [options.initialState={}] - Pre-filled form values.
7
+ * @param {Function} [options.t] - Optional translation function.
8
+ * @returns {UIForm} Form instance ready for input.
9
+ */
10
+ export function generateForm(BodyClass: Function, options?: {
11
+ initialState?: any;
12
+ t?: Function | undefined;
13
+ }): UIForm;
14
+ /**
15
+ * Unified UI Adapter that handles both input and output operations.
16
+ * It manages user interactions and rendering of messages, forms, and progress.
17
+ *
18
+ * @class UiAdapter
19
+ * @extends EventProcessor
20
+ *
21
+ * @example
22
+ * const adapter = new UiAdapter()
23
+ * adapter.output = new View()
24
+ *
25
+ * const result = await adapter.requireInput(new LoginMessage())
26
+ * console.log(result) // { username: "user", password: "pass" }
27
+ */
28
+ export default class UiAdapter extends EventProcessor {
29
+ static CancelError: typeof CancelError;
30
+ /** @returns {typeof CancelError} */
31
+ get CancelError(): typeof CancelError;
32
+ /** @type {OutputAdapter | null} Output interface for rendering */
33
+ output: OutputAdapter | null;
34
+ /**
35
+ * Starts listening for input and emits an `input` event.
36
+ *
37
+ * @returns {void}
38
+ */
39
+ start(): void;
40
+ /**
41
+ * Stops listening for input and output streams.
42
+ * Default implementation does nothing; override in subclasses to perform cleanup.
43
+ *
44
+ * @returns {void}
45
+ */
46
+ stop(): void;
47
+ /**
48
+ * Checks whether the adapter is ready to receive input.
49
+ *
50
+ * @returns {boolean} Always true in base class; override for specific checks.
51
+ */
52
+ isReady(): boolean;
53
+ /**
54
+ * Helper to ask a question.
55
+ * Must be implemented by subclasses.
56
+ *
57
+ * @param {string} question - Question to ask the user.
58
+ * @returns {Promise<string>} User's response.
59
+ * @throws {Error} If not implemented in subclass.
60
+ */
61
+ ask(question: string): Promise<string>;
62
+ /**
63
+ * Generic selection prompt.
64
+ * Must be implemented by subclasses.
65
+ *
66
+ * @param {object} config - Selection configuration.
67
+ * @param {string[]} [config.options=[]] - List of options to choose from.
68
+ * @returns {Promise<{ index: number, value: string | null }>} Selected option.
69
+ * @throws {Error} If not implemented in subclass.
70
+ */
71
+ select(config: {
72
+ options?: string[] | undefined;
73
+ }): Promise<{
74
+ index: number;
75
+ value: string | null;
76
+ }>;
77
+ /**
78
+ * Ensures a message's body is fully and validly filled.
79
+ * Generates a form from the message's static Body schema,
80
+ * then iteratively collects input until all fields are valid or cancelled.
81
+ *
82
+ * @template {UIMessage} T
83
+ * @param {T} msg - Message instance needing input.
84
+ * @returns {Promise<T['body']>} Updated and validated message body.
85
+ *
86
+ * @example
87
+ * const body = await adapter.requireInput(new LoginMessage({ body: { username: "user" } }))
88
+ * // → prompts for password, returns { username: "user", password: "..." }
89
+ */
90
+ requireInput<T extends UIMessage>(msg: T): Promise<T["body"]>;
91
+ /**
92
+ * Renders a message to the user interface.
93
+ * Must be implemented by subclasses.
94
+ *
95
+ * @param {UIMessage} message - Message to render.
96
+ * @emits rendered
97
+ * @throws {Error} If not implemented in subclass.
98
+ */
99
+ render(message: UIMessage): void;
100
+ }
101
+ import UIForm from "./Form/Form.js";
102
+ import EventProcessor from "@nan0web/event/oop";
103
+ import CancelError from "./Error/CancelError.js";
104
+ import UIMessage from "./Message/Message.js";
@@ -1,10 +1,9 @@
1
1
  export { default as InputAdapter } from "./InputAdapter.js";
2
2
  export { default as OutputAdapter } from "./OutputAdapter.js";
3
3
  export { default as UIStream } from "./Stream.js";
4
- export { default as UIMessage } from "./Message/Message.js";
5
- export { default as InputMessage } from "./Message/InputMessage.js";
6
- export { default as OutputMessage } from "./Message/OutputMessage.js";
4
+ export { default as UiMessage } from "./Message/Message.js";
7
5
  export { default as FormMessage } from "./Form/Message.js";
8
6
  export { default as FormInput } from "./Form/Input.js";
9
7
  export { default as UIForm } from "./Form/Form.js";
8
+ export { default as UiAdapter } from "./UiAdapter.js";
10
9
  export { default as Error, CancelError } from "./Error/index.js";
package/types/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export { default as FormMessage } from "./core/Form/Message.js";
2
2
  export { default as FormInput } from "./core/Form/Input.js";
3
3
  export { default as InputAdapter } from "./core/InputAdapter.js";
4
- export { default as InputMessage } from "./core/Message/InputMessage.js";
5
4
  export { default as OutputAdapter } from "./core/OutputAdapter.js";
6
5
  export { default as OutputMessage } from "./core/Message/OutputMessage.js";
7
- export { default as UIForm } from "./core/Form/Form.js";
8
- export { default as UIMessage } from "./core/Message/Message.js";
9
- export { default as UIStream } from "./core/Stream.js";
6
+ export { default as UiForm } from "./core/Form/Form.js";
7
+ export { default as UiMessage } from "./core/Message/Message.js";
8
+ export { default as UiStream } from "./core/Stream.js";
9
+ export { default as UiAdapter } from "./core/UiAdapter.js";
10
10
  import Frame from "./Frame/Frame.js";
11
11
  import FrameProps from "./Frame/Props.js";
12
12
  import Locale from "./Locale.js";