@nan0web/ui 1.0.2 → 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 (58) hide show
  1. package/README.md +19 -54
  2. package/package.json +21 -17
  3. package/src/App/Core/CoreApp.js +14 -19
  4. package/src/App/Core/UI.js +4 -50
  5. package/src/App/Core/Widget.js +4 -6
  6. package/src/App/User/Command/Message.js +23 -37
  7. package/src/App/User/Command/index.js +3 -8
  8. package/src/App/User/UserApp.js +32 -27
  9. package/src/App/User/UserUI.js +4 -4
  10. package/src/App/User/index.js +0 -6
  11. package/src/App/index.js +0 -3
  12. package/src/README.md.js +33 -57
  13. package/src/StdIn.js +12 -15
  14. package/src/View/View.js +5 -5
  15. package/src/core/Error/index.js +9 -0
  16. package/src/core/Form/Form.js +43 -23
  17. package/src/core/Form/Input.js +16 -7
  18. package/src/core/Form/Message.js +6 -8
  19. package/src/core/InputAdapter.js +6 -2
  20. package/src/core/Message/Message.js +109 -19
  21. package/src/core/Message/OutputMessage.js +8 -8
  22. package/src/core/Message/index.js +3 -4
  23. package/src/core/Stream.js +10 -10
  24. package/src/core/UiAdapter.js +189 -0
  25. package/src/core/index.js +5 -6
  26. package/src/index.js +5 -4
  27. package/types/App/Core/CoreApp.d.ts +9 -9
  28. package/types/App/Core/UI.d.ts +5 -15
  29. package/types/App/Core/Widget.d.ts +7 -8
  30. package/types/App/User/Command/Message.d.ts +15 -29
  31. package/types/App/User/Command/Options.d.ts +9 -2
  32. package/types/App/User/Command/index.d.ts +3 -7
  33. package/types/App/User/UserApp.d.ts +19 -9
  34. package/types/App/User/UserUI.d.ts +0 -9
  35. package/types/App/User/index.d.ts +0 -4
  36. package/types/App/index.d.ts +1 -3
  37. package/types/Frame/Frame.d.ts +5 -5
  38. package/types/StdIn.d.ts +13 -13
  39. package/types/View/View.d.ts +9 -9
  40. package/types/core/Error/index.d.ts +6 -0
  41. package/types/core/Form/Form.d.ts +14 -11
  42. package/types/core/Form/Input.d.ts +20 -7
  43. package/types/core/Form/Message.d.ts +5 -4
  44. package/types/core/InputAdapter.d.ts +2 -0
  45. package/types/core/Intent.d.ts +91 -0
  46. package/types/core/Message/InputMessage.d.ts +5 -5
  47. package/types/core/Message/Message.d.ts +58 -15
  48. package/types/core/Message/OutputMessage.d.ts +4 -4
  49. package/types/core/Message/index.d.ts +3 -4
  50. package/types/core/Stream.d.ts +5 -4
  51. package/types/core/StreamEntry.d.ts +1 -1
  52. package/types/core/UiAdapter.d.ts +104 -0
  53. package/types/core/index.d.ts +3 -3
  54. package/types/index.d.ts +5 -4
  55. package/src/App/Command/Options.js +0 -78
  56. package/src/App/Command/index.js +0 -9
  57. package/src/App/User/Command/Options.js +0 -48
  58. package/src/core/Message/InputMessage.js +0 -119
@@ -2,7 +2,15 @@ export default UserAppCommandOptions;
2
2
  /**
3
3
  * Extends CommandOptions to include user-specific options.
4
4
  */
5
- declare class UserAppCommandOptions extends CommandOptions {
5
+ declare class UserAppCommandOptions {
6
+ /**
7
+ * Default option values including inherited ones.
8
+ * @type {object}
9
+ * @property {boolean} help - Whether help is requested
10
+ * @property {string} cwd - Current working directory
11
+ * @property {string} user - User name
12
+ */
13
+ static DEFAULTS: object;
6
14
  /**
7
15
  * Creates a UserAppCommandOptions instance from the given props.
8
16
  * @param {UserAppCommandOptions|object} props - The properties to create from
@@ -24,4 +32,3 @@ declare class UserAppCommandOptions extends CommandOptions {
24
32
  /** @type {string} User name */
25
33
  user: string;
26
34
  }
27
- import CommandOptions from "../../Command/Options.js";
@@ -1,8 +1,4 @@
1
- declare namespace _default {
2
- export { CommandMessage as Message };
3
- export { CommandOptions as Options };
4
- }
5
- export default _default;
1
+ export default CommandMessage;
6
2
  import CommandMessage from "./Message.js";
7
- import CommandOptions from "./Options.js";
8
- export { CommandMessage, CommandOptions };
3
+ import DepsCommand from "./Message.js";
4
+ export { CommandMessage, DepsCommand };
@@ -1,31 +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 {
8
- /** @type {CommandMessage} Starting command parsed from argv */
9
- startCommand: CommandMessage;
6
+ export default class UserApp extends CoreApp {
7
+ /**
8
+ * Creates a new UserApp instance.
9
+ * @param {Partial<CoreApp>} [props={}] - UserApp properties
10
+ */
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>;
10
19
  /**
11
20
  * Set user data from params.
12
- * @param {CommandMessage} cmd - Command message with user data
21
+ * @param {UserAppCommandMessage} cmd - Command message with user data
13
22
  * @param {UserUI} ui - UI instance
14
23
  * @returns {Promise<{ message: string }>} Welcome message
15
24
  */
16
- setUser(cmd: CommandMessage, ui: UserUI): Promise<{
25
+ setUser(cmd: UserAppCommandMessage, ui: UserUI): Promise<{
17
26
  message: string;
18
27
  }>;
19
28
  /**
20
29
  * Show welcome message for current user.
21
- * @param {CommandMessage} cmd - Command message
30
+ * @param {UserAppCommandMessage} cmd - Command message
22
31
  * @param {UserUI} ui - UI instance
23
32
  * @returns {Promise<string[][]>} Welcome view output
24
33
  */
25
- welcome(cmd: CommandMessage, ui: UserUI): Promise<string[][]>;
34
+ welcome(cmd: UserAppCommandMessage, ui: UserUI): Promise<string[][]>;
26
35
  user: User | undefined;
27
36
  }
28
37
  import CoreApp from "../Core/CoreApp.js";
29
- import { CommandMessage } from "./Command/index.js";
38
+ import DepsCommand from "./Command/Message.js";
30
39
  import UserUI from "./UserUI.js";
40
+ import UserAppCommandMessage from "./Command/Message.js";
31
41
  import User from "../../Model/User/User.js";
@@ -5,14 +5,5 @@ declare const UserUI_base: typeof import("../Core/UI.js").default;
5
5
  * Allows user to change user data to see another Welcome view.
6
6
  */
7
7
  export default class UserUI extends UserUI_base {
8
- /**
9
- * Convert raw input to CommandMessage array.
10
- * If user.name provided in rawInput, use it directly.
11
- * Otherwise ask user for name.
12
- * @param {any} rawInput - Raw input to convert
13
- * @returns {CommandMessage[]} Array of command messages
14
- */
15
- convertInput(rawInput: any): CommandMessage[];
16
8
  }
17
- import { CommandMessage } from "./Command/index.js";
18
9
  export {};
@@ -1,10 +1,6 @@
1
1
  declare namespace _default {
2
2
  export { UserApp as App };
3
3
  export { UserUI as UI };
4
- export let Command: {
5
- Message: typeof import("./Command/Message.js").default;
6
- Options: typeof import("./Command/Options.js").default;
7
- };
8
4
  }
9
5
  export default _default;
10
6
  import UserApp from "./UserApp.js";
@@ -1,14 +1,12 @@
1
1
  declare namespace _default {
2
2
  export { Core };
3
3
  export { User };
4
- export { Command };
5
4
  export { Scenario };
6
5
  export { UI };
7
6
  }
8
7
  export default _default;
9
8
  import Core from "./Core/index.js";
10
9
  import User from "./User/index.js";
11
- import Command from "./Command/index.js";
12
10
  import Scenario from "./Scenario.js";
13
11
  import UI from "./Core/UI.js";
14
- export { Core, User, Command, Scenario, UI };
12
+ export { Core, User, Scenario, UI };
@@ -85,19 +85,19 @@ export default class Frame {
85
85
  * @param {number} [lines=1] - Number of lines to move up.
86
86
  * @returns {string} ANSI escape code for cursor movement.
87
87
  */
88
- static cursorUp(lines?: number | undefined): string;
88
+ static cursorUp(lines?: number): string;
89
89
  /**
90
90
  * Move cursor down by specified lines.
91
91
  * @param {number} [lines=1] - Number of lines to move down.
92
92
  * @returns {string} ANSI escape code for cursor movement.
93
93
  */
94
- static cursorDown(lines?: number | undefined): string;
94
+ static cursorDown(lines?: number): string;
95
95
  /**
96
96
  * Clear the current line.
97
97
  * @param {string} [str="\r"] - String to append after clearing.
98
98
  * @returns {string} ANSI escape code for line clearing followed by the string.
99
99
  */
100
- static clearLine(str?: string | undefined): string;
100
+ static clearLine(str?: string): string;
101
101
  /**
102
102
  * Clear the entire screen.
103
103
  * @returns {string} ANSI escape codes for screen clearing.
@@ -119,7 +119,7 @@ export default class Frame {
119
119
  imprint?: string | undefined;
120
120
  renderMethod?: string | undefined;
121
121
  defaultProps?: FrameProps | undefined;
122
- } | undefined);
122
+ });
123
123
  /**
124
124
  * @example
125
125
  * ```js
@@ -163,7 +163,7 @@ export default class Frame {
163
163
  render(options?: {
164
164
  method?: string | undefined;
165
165
  props?: FrameProps | undefined;
166
- } | undefined): string;
166
+ }): string;
167
167
  /**
168
168
  * Convert the frame to its string representation.
169
169
  * @returns {string} The frame's imprint.
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 {
@@ -14,7 +14,7 @@ export default class View {
14
14
  * @param {RenderOptions} [options]
15
15
  * @returns {Frame}
16
16
  */
17
- static fixFrame(frame: Frame, options?: RenderOptions | undefined): Frame;
17
+ static fixFrame(frame: Frame, options?: RenderOptions): Frame;
18
18
  /**
19
19
  * @param {object} [input]
20
20
  * @param {StdIn} [input.stdin]
@@ -37,7 +37,7 @@ export default class View {
37
37
  windowSize?: number[] | undefined;
38
38
  components?: Map<string, ComponentFn> | undefined;
39
39
  renderMethod?: string | undefined;
40
- } | undefined);
40
+ });
41
41
  /** @type {StdIn} */
42
42
  stdin: StdIn;
43
43
  /** @type {StdOut} */
@@ -68,7 +68,7 @@ export default class View {
68
68
  * @param {RenderOptions} [options]
69
69
  * @returns {(value: Frame|string|string[], ...args: any) => Frame}
70
70
  */
71
- render(shouldRender?: number | boolean | Function | ComponentFn | undefined, options?: RenderOptions | undefined): (value: Frame | string | string[], ...args: any) => Frame;
71
+ render(shouldRender?: boolean | number | Function | ComponentFn, options?: RenderOptions): (value: Frame | string | string[], ...args: any) => Frame;
72
72
  clear(shouldRender?: number): Frame;
73
73
  progress(shouldRender?: boolean): (value: any) => Frame;
74
74
  t(value: any): any;
@@ -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";
@@ -0,0 +1,6 @@
1
+ export { CancelError };
2
+ declare namespace _default {
3
+ export { CancelError };
4
+ }
5
+ export default _default;
6
+ import CancelError from "./CancelError.js";
@@ -10,17 +10,17 @@
10
10
  */
11
11
  export default class UIForm extends FormMessage {
12
12
  /** @type {Object<string,Function>} */
13
- static _validators: {
13
+ static _validations: {
14
14
  [x: string]: Function;
15
15
  };
16
16
  /**
17
- * Register a custom validator that can be referenced by name in a schema.
17
+ * Register a custom validation that can be referenced by name in a schema.
18
18
  *
19
- * @param {string} name - Identifier used in schema.validator.
19
+ * @param {string} name - Identifier used in schema.validation.
20
20
  * @param {(value:any)=>true|string} fn - Function returns true if valid,
21
21
  * otherwise returns an error message.
22
22
  */
23
- static addValidator(name: string, fn: (value: any) => true | string): void;
23
+ static addValidation(name: string, fn: (value: any) => true | string): void;
24
24
  /**
25
25
  * @param {*} input
26
26
  * @returns {UIForm}
@@ -42,7 +42,7 @@ export default class UIForm extends FormMessage {
42
42
  */
43
43
  static parse(data: any, overrides?: {
44
44
  [x: string]: Partial<FormInput>;
45
- } | undefined): UIForm;
45
+ }): UIForm;
46
46
  /**
47
47
  * Create a new UIForm.
48
48
  *
@@ -57,7 +57,7 @@ export default class UIForm extends FormMessage {
57
57
  fields?: FormInput[] | undefined;
58
58
  state?: any;
59
59
  schema?: any;
60
- } | undefined);
60
+ });
61
61
  /** @type {FormInput[]} */ fields: FormInput[];
62
62
  /** @type {Object} */ state: any;
63
63
  /** @type {string} */ title: string;
@@ -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
  *
@@ -118,6 +115,12 @@ export default class UIForm extends FormMessage {
118
115
  isValid: boolean;
119
116
  errors: any;
120
117
  };
118
+ /**
119
+ * Serialises the form to a plain JSON object.
120
+ *
121
+ * @returns {Object}
122
+ */
123
+ toJSON(): any;
121
124
  }
122
125
  import FormMessage from "./Message.js";
123
126
  import FormInput from "./Input.js";
@@ -1,3 +1,10 @@
1
+ /**
2
+ * @typedef {Object} Filter
3
+ * @property {string} [q=""]
4
+ * @property {number} [offset=0]
5
+ * @property {number} [limit=36]
6
+ */
7
+ /** @typedef {Array<string> | ((filter: Filter) => Promise<string[]>)} InputOptions */
1
8
  /**
2
9
  * Form input field descriptor.
3
10
  *
@@ -8,7 +15,7 @@
8
15
  * @property {boolean} required - Whether the field is required.
9
16
  * @property {string} placeholder - Placeholder text.
10
17
  * @property {Array<string>} options - Select options (if type is 'select').
11
- * @property {Function|null} validator - Custom validation function.
18
+ * @property {Function|null} validation - Custom validation function.
12
19
  * @property {*} defaultValue - Default value.
13
20
  */
14
21
  export default class FormInput {
@@ -37,8 +44,8 @@ export default class FormInput {
37
44
  * @param {string} [props.type='text'] - Input type.
38
45
  * @param {boolean} [props.required=false] - Is required.
39
46
  * @param {string} [props.placeholder=''] - Placeholder.
40
- * @param {Array<string>} [props.options=[]] - Select options.
41
- * @param {Function} [props.validator=null] - Custom validator.
47
+ * @param {InputOptions} [props.options=[]] - Select options or async function to retrieve data with the search and page.
48
+ * @param {Function} [props.validation=null] - Custom validation.
42
49
  * @param {*} [props.defaultValue=null] - Default value.
43
50
  */
44
51
  constructor(props: {
@@ -47,8 +54,8 @@ export default class FormInput {
47
54
  type?: string | undefined;
48
55
  required?: boolean | undefined;
49
56
  placeholder?: string | undefined;
50
- options?: string[] | undefined;
51
- validator?: Function | undefined;
57
+ options?: InputOptions | undefined;
58
+ validation?: Function | undefined;
52
59
  defaultValue?: any;
53
60
  });
54
61
  /** @type {string} */ name: string;
@@ -56,8 +63,8 @@ export default class FormInput {
56
63
  /** @type {string} */ type: string;
57
64
  /** @type {boolean} */ required: boolean;
58
65
  /** @type {string} */ placeholder: string;
59
- /** @type {Array<string>} */ options: Array<string>;
60
- /** @type {Function|null} */ validator: Function | null;
66
+ /** @type {InputOptions} */ options: InputOptions;
67
+ /** @type {import("@nan0web/co").ValidateFn|null} */ validation: import("@nan0web/co").ValidateFn | null;
61
68
  /** @type {*} */ defaultValue: any;
62
69
  requireValidType(): void;
63
70
  /**
@@ -67,3 +74,9 @@ export default class FormInput {
67
74
  */
68
75
  toJSON(): any;
69
76
  }
77
+ export type Filter = {
78
+ q?: string | undefined;
79
+ offset?: number | undefined;
80
+ limit?: number | undefined;
81
+ };
82
+ export type InputOptions = Array<string> | ((filter: Filter) => Promise<string[]>);
@@ -1,10 +1,11 @@
1
1
  /**
2
- * FormMessage – specialized OutputMessage 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 OutputMessage
6
+ * @extends UiMessage
6
7
  */
7
- export default class FormMessage extends OutputMessage {
8
+ export default class FormMessage extends UiMessage {
8
9
  data: any;
9
10
  schema: any;
10
11
  /**
@@ -25,4 +26,4 @@ export default class FormMessage extends OutputMessage {
25
26
  errors: any;
26
27
  };
27
28
  }
28
- import OutputMessage from "../Message/OutputMessage.js";
29
+ import UiMessage from "../Message/Message.js";
@@ -6,6 +6,8 @@
6
6
  */
7
7
  export default class InputAdapter extends Event {
8
8
  static CancelError: typeof CancelError;
9
+ /** @returns {typeof CancelError} */
10
+ get CancelError(): typeof CancelError;
9
11
  /**
10
12
  * Starts listening for input and emits an `input` event.
11
13
  *
@@ -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,4 +1,4 @@
1
- /** @typedef {Message | string | null} InputMessageValue */
1
+ /** @typedef {Partial<Message> | null} InputMessageValue */
2
2
  /**
3
3
  * Represents a message input with value, options, and metadata.
4
4
  */
@@ -13,7 +13,7 @@ export default class InputMessage {
13
13
  /**
14
14
  * Creates a new InputMessage instance.
15
15
  * @param {object} props - Input message properties
16
- * @param {InputMessageValue} [props.value=""] - Input value
16
+ * @param {InputMessageValue} [props.value=null] - Input value
17
17
  * @param {string[]|string} [props.options=[]] - Available options
18
18
  * @param {boolean} [props.waiting=false] - Waiting state flag
19
19
  * @param {boolean} [props.escaped=false] - Sets value to escape when true
@@ -24,8 +24,8 @@ export default class InputMessage {
24
24
  waiting?: boolean | undefined;
25
25
  escaped?: boolean | undefined;
26
26
  });
27
- /** @type {InputMessageValue} Input value */
28
- value: InputMessageValue;
27
+ /** @type {Message} Input value */
28
+ value: Message;
29
29
  /** @type {string[]} Available options for this input */
30
30
  options: string[];
31
31
  /** @type {boolean} Whether this input is waiting for response */
@@ -67,5 +67,5 @@ export default class InputMessage {
67
67
  toString(): string;
68
68
  #private;
69
69
  }
70
- export type InputMessageValue = Message | string | null;
70
+ export type InputMessageValue = Partial<Message> | null;
71
71
  import { Message } from "@nan0web/co";