@nan0web/ui 1.0.2 → 1.0.3

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 (44) hide show
  1. package/README.md +2 -35
  2. package/package.json +7 -2
  3. package/src/App/Core/CoreApp.js +14 -19
  4. package/src/App/Core/UI.js +5 -5
  5. package/src/App/User/UserApp.js +4 -19
  6. package/src/App/User/UserUI.js +4 -4
  7. package/src/App/User/index.js +0 -6
  8. package/src/App/index.js +0 -3
  9. package/src/README.md.js +3 -27
  10. package/src/StdIn.js +1 -3
  11. package/src/core/Error/index.js +9 -0
  12. package/src/core/Form/Form.js +36 -18
  13. package/src/core/Form/Input.js +16 -7
  14. package/src/core/Form/Message.js +6 -9
  15. package/src/core/InputAdapter.js +4 -0
  16. package/src/core/Message/InputMessage.js +11 -11
  17. package/src/core/Message/OutputMessage.js +1 -1
  18. package/src/core/index.js +2 -0
  19. package/src/index.js +1 -0
  20. package/types/App/Core/CoreApp.d.ts +9 -9
  21. package/types/App/Core/UI.d.ts +5 -5
  22. package/types/App/Core/Widget.d.ts +1 -1
  23. package/types/App/User/Command/Message.d.ts +2 -3
  24. package/types/App/User/Command/Options.d.ts +9 -2
  25. package/types/App/User/Command/index.d.ts +1 -4
  26. package/types/App/User/UserApp.d.ts +10 -7
  27. package/types/App/User/UserUI.d.ts +0 -9
  28. package/types/App/User/index.d.ts +0 -4
  29. package/types/App/index.d.ts +1 -3
  30. package/types/Frame/Frame.d.ts +5 -5
  31. package/types/View/View.d.ts +3 -3
  32. package/types/core/Error/index.d.ts +6 -0
  33. package/types/core/Form/Form.d.ts +12 -6
  34. package/types/core/Form/Input.d.ts +20 -7
  35. package/types/core/Form/Message.d.ts +10 -4
  36. package/types/core/InputAdapter.d.ts +2 -0
  37. package/types/core/Message/InputMessage.d.ts +5 -5
  38. package/types/core/Message/OutputMessage.d.ts +1 -1
  39. package/types/core/Stream.d.ts +1 -1
  40. package/types/core/StreamEntry.d.ts +1 -1
  41. package/types/core/index.d.ts +1 -0
  42. package/types/index.d.ts +1 -0
  43. package/src/App/Command/Options.js +0 -78
  44. package/src/App/Command/index.js +0 -9
@@ -1,14 +1,14 @@
1
1
  import { notEmpty } from "@nan0web/types"
2
2
  import { Message } from "@nan0web/co"
3
3
 
4
- /** @typedef {Message | string | null} InputMessageValue */
4
+ /** @typedef {Partial<Message> | null} InputMessageValue */
5
5
 
6
6
  /**
7
7
  * Represents a message input with value, options, and metadata.
8
8
  */
9
9
  export default class InputMessage {
10
10
  static ESCAPE = String.fromCharCode(27)
11
- /** @type {InputMessageValue} Input value */
11
+ /** @type {Message} Input value */
12
12
  value
13
13
 
14
14
  /** @type {string[]} Available options for this input */
@@ -23,17 +23,17 @@ export default class InputMessage {
23
23
  /**
24
24
  * Creates a new InputMessage instance.
25
25
  * @param {object} props - Input message properties
26
- * @param {InputMessageValue} [props.value=""] - Input value
26
+ * @param {InputMessageValue} [props.value=null] - Input value
27
27
  * @param {string[]|string} [props.options=[]] - Available options
28
28
  * @param {boolean} [props.waiting=false] - Waiting state flag
29
29
  * @param {boolean} [props.escaped=false] - Sets value to escape when true
30
30
  */
31
31
  constructor(props = {}) {
32
32
  if ("string" === typeof props) {
33
- props = { value: props }
33
+ props = { value: { body: props } }
34
34
  }
35
35
  const {
36
- value = "",
36
+ value = { body: "" },
37
37
  waiting = false,
38
38
  options = [],
39
39
  escaped = false,
@@ -43,10 +43,7 @@ export default class InputMessage {
43
43
 
44
44
  // Properly handle string options by converting to array
45
45
  this.options = Array.isArray(options) ? options.map(String) : [String(options)]
46
- this.value = String(value)
47
- if (!this.value && escaped) {
48
- this.value = this.ESCAPE
49
- }
46
+ this.value = Message.from(escaped ? { body: this.ESCAPE } : value)
50
47
  }
51
48
 
52
49
  /**
@@ -54,6 +51,9 @@ export default class InputMessage {
54
51
  * @returns {boolean} True if value is empty or null, false otherwise
55
52
  */
56
53
  get empty() {
54
+ if (this.value instanceof Message) {
55
+ return this.value.empty
56
+ }
57
57
  return null === this.value || 0 === String(this.value).length
58
58
  }
59
59
 
@@ -78,7 +78,7 @@ export default class InputMessage {
78
78
  * @returns {boolean} True if input value is escape sequence, false otherwise
79
79
  */
80
80
  get escaped() {
81
- return this.ESCAPE === this.value
81
+ return this.ESCAPE === this.value.body
82
82
  }
83
83
 
84
84
  /**
@@ -87,7 +87,7 @@ export default class InputMessage {
87
87
  */
88
88
  get isValid() {
89
89
  // An input is valid only if it has a non-empty value and is not an escape sequence
90
- return notEmpty(this.value) && this.value !== this.ESCAPE
90
+ return notEmpty(this.value) && this.value.body !== this.ESCAPE
91
91
  }
92
92
 
93
93
  /**
@@ -140,4 +140,4 @@ export default class OutputMessage extends UIMessage {
140
140
  if (input instanceof OutputMessage) return input
141
141
  return new OutputMessage(input)
142
142
  }
143
- }
143
+ }
package/src/core/index.js CHANGED
@@ -11,3 +11,5 @@ export { default as OutputMessage } from "./Message/OutputMessage.js"
11
11
  export { default as FormMessage } from "./Form/Message.js"
12
12
  export { default as FormInput } from "./Form/Input.js"
13
13
  export { default as UIForm } from "./Form/Form.js"
14
+
15
+ export { default as Error, CancelError } from "./Error/index.js"
package/src/index.js CHANGED
@@ -32,3 +32,4 @@ export { default as OutputMessage } from "./core/Message/OutputMessage.js"
32
32
  export { default as UIForm } from "./core/Form/Form.js"
33
33
  export { default as UIMessage } from "./core/Message/Message.js"
34
34
  export { default as UIStream } from "./core/Stream.js"
35
+ export { default as Error, CancelError } from "./core/Error/index.js"
@@ -9,12 +9,12 @@ export default class CoreApp {
9
9
  * @param {object} props - CoreApp properties
10
10
  * @param {string} [props.name="CoreApp"] - App name
11
11
  * @param {object} [props.state={}] - Initial state object
12
- * @param {string[]} [props.argv=[]] - Command line arguments to parse
12
+ * @param {Message} [props.startCommand=new Message()] - Command line arguments to parse
13
13
  */
14
14
  constructor(props?: {
15
15
  name?: string | undefined;
16
16
  state?: object;
17
- argv?: string[] | undefined;
17
+ startCommand?: Message | undefined;
18
18
  });
19
19
  /** @type {string} App name */
20
20
  name: string;
@@ -22,8 +22,8 @@ export default class CoreApp {
22
22
  commands: Map<string, CommandFn>;
23
23
  /** @type {object} App state */
24
24
  state: object;
25
- /** @type {CommandMessage} Starting command parsed from argv */
26
- startCommand: CommandMessage;
25
+ /** @type {Message} Starting command parsed from argv */
26
+ startCommand: Message;
27
27
  /**
28
28
  * Sets app state.
29
29
  * @param {string|object} state - State key or object with multiple keys
@@ -44,19 +44,19 @@ export default class CoreApp {
44
44
  toString(): string;
45
45
  /**
46
46
  * Process a command message.
47
- * @param {CommandMessage} commandMessage - Command to process
47
+ * @param {Message} msg - Command to process
48
48
  * @param {UI} ui - UI instance to use for rendering
49
49
  * @returns {Promise<any>} Output of the command
50
50
  * @throws {Error} If the command is not registered
51
51
  */
52
- processCommand(commandMessage: CommandMessage, ui: UI): Promise<any>;
52
+ processCommand(msg: Message, ui: UI): Promise<any>;
53
53
  /**
54
54
  * Process an array of command messages sequentially.
55
- * @param {CommandMessage[]} commandMessages - Array of commands to process
55
+ * @param {Message[]} Messages - Array of commands to process
56
56
  * @param {UI} ui - UI instance to use for rendering
57
57
  * @returns {Promise<any[]>} Array of command outputs
58
58
  */
59
- processCommands(commandMessages: CommandMessage[], ui: UI): Promise<any[]>;
59
+ processCommands(Messages: Message[], ui: UI): Promise<any[]>;
60
60
  /**
61
61
  * Select a command to run. Must be implemented by subclasses.
62
62
  * @param {UI} ui - UI instance for interaction
@@ -66,5 +66,5 @@ export default class CoreApp {
66
66
  selectCommand(ui: UI): Promise<string>;
67
67
  }
68
68
  export type CommandFn = Function;
69
- import { CommandMessage } from "../Command/index.js";
69
+ import { Message } from "@nan0web/co";
70
70
  import UI from "./UI.js";
@@ -11,17 +11,17 @@ declare class UI extends Widget {
11
11
  * @param {CoreApp} app - The app to connect to this UI
12
12
  * @param {View} [view] - View instance for rendering (default: new View())
13
13
  */
14
- constructor(app: CoreApp, view?: View | undefined);
14
+ constructor(app: CoreApp, view?: View);
15
15
  /** @type {CoreApp} The app instance connected to this UI */
16
16
  app: CoreApp;
17
17
  /**
18
- * Convert raw input to CommandMessage array.
18
+ * Convert raw input to Message array.
19
19
  * Must be implemented by subclasses.
20
20
  * @param {any} rawInput - Raw input to convert
21
- * @returns {CommandMessage[]} Array of command messages
21
+ * @returns {Message[]} Array of command messages
22
22
  * @throws {Error} Always thrown as this method must be implemented by subclasses
23
23
  */
24
- convertInput(rawInput: any): CommandMessage[];
24
+ convertInput(rawInput: any): Message[];
25
25
  /**
26
26
  * Process input, run commands on app, and output results.
27
27
  * Supports progress callback.
@@ -45,5 +45,5 @@ declare class UI extends Widget {
45
45
  }
46
46
  import Widget from "./Widget.js";
47
47
  import CoreApp from "./CoreApp.js";
48
- import { CommandMessage } from "../Command/index.js";
48
+ import { Message } from "@nan0web/co";
49
49
  import View from "../../View/View.js";
@@ -11,7 +11,7 @@ declare class Widget extends EventProcessor {
11
11
  * Creates a new Widget instance.
12
12
  * @param {View} [view] - View instance (default: new View())
13
13
  */
14
- constructor(view?: View | undefined);
14
+ constructor(view?: View);
15
15
  /** @type {View} The view associated with this widget */
16
16
  view: View;
17
17
  /**
@@ -2,7 +2,7 @@ export default UserAppCommandMessage;
2
2
  /**
3
3
  * Extends Command.Message to include user-specific command options.
4
4
  */
5
- declare class UserAppCommandMessage extends CommandMessage {
5
+ declare class UserAppCommandMessage {
6
6
  /**
7
7
  * Parses an array of strings into a UserAppCommandMessage.
8
8
  * @param {string[] | string} value - Arguments to parse
@@ -22,9 +22,8 @@ declare class UserAppCommandMessage extends CommandMessage {
22
22
  /**
23
23
  * @param {Partial<UserAppCommandOptions>} value
24
24
  */
25
- set opts(arg: UserAppCommandOptions);
25
+ set opts(value: Partial<UserAppCommandOptions>);
26
26
  /** @returns {UserAppCommandOptions} */
27
27
  get opts(): UserAppCommandOptions;
28
28
  }
29
- import { CommandMessage } from "../../Command/index.js";
30
29
  import UserAppCommandOptions from "./Options.js";
@@ -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,7 +1,4 @@
1
- declare namespace _default {
2
- export { CommandMessage as Message };
3
- export { CommandOptions as Options };
4
- }
1
+ declare const _default: any;
5
2
  export default _default;
6
3
  import CommandMessage from "./Message.js";
7
4
  import CommandOptions from "./Options.js";
@@ -5,27 +5,30 @@ export default UserApp;
5
5
  * User can change user data to see another Welcome view.
6
6
  */
7
7
  declare class UserApp extends CoreApp {
8
- /** @type {CommandMessage} Starting command parsed from argv */
9
- startCommand: CommandMessage;
8
+ /**
9
+ * Creates a new UserApp instance.
10
+ * @param {Partial<CoreApp>} [props={}] - UserApp properties
11
+ */
12
+ constructor(props?: Partial<CoreApp>);
10
13
  /**
11
14
  * Set user data from params.
12
- * @param {CommandMessage} cmd - Command message with user data
15
+ * @param {Message} cmd - Command message with user data
13
16
  * @param {UserUI} ui - UI instance
14
17
  * @returns {Promise<{ message: string }>} Welcome message
15
18
  */
16
- setUser(cmd: CommandMessage, ui: UserUI): Promise<{
19
+ setUser(cmd: Message, ui: UserUI): Promise<{
17
20
  message: string;
18
21
  }>;
19
22
  /**
20
23
  * Show welcome message for current user.
21
- * @param {CommandMessage} cmd - Command message
24
+ * @param {Message} cmd - Command message
22
25
  * @param {UserUI} ui - UI instance
23
26
  * @returns {Promise<string[][]>} Welcome view output
24
27
  */
25
- welcome(cmd: CommandMessage, ui: UserUI): Promise<string[][]>;
28
+ welcome(cmd: Message, ui: UserUI): Promise<string[][]>;
26
29
  user: User | undefined;
27
30
  }
28
31
  import CoreApp from "../Core/CoreApp.js";
29
- import { CommandMessage } from "./Command/index.js";
32
+ import { Message } from "@nan0web/co";
30
33
  import UserUI from "./UserUI.js";
31
34
  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.
@@ -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;
@@ -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;
@@ -118,6 +118,12 @@ export default class UIForm extends FormMessage {
118
118
  isValid: boolean;
119
119
  errors: any;
120
120
  };
121
+ /**
122
+ * Serialises the form to a plain JSON object.
123
+ *
124
+ * @returns {Object}
125
+ */
126
+ toJSON(): any;
121
127
  }
122
128
  import FormMessage from "./Message.js";
123
129
  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 {Function|null} */ validation: Function | 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,16 @@
1
1
  /**
2
- * FormMessage – specialized OutputMessage for forms.
2
+ * FormMessage – specialized InputMessage for forms.
3
3
  *
4
4
  * @class FormMessage
5
- * @extends OutputMessage
5
+ * @extends InputMessage
6
6
  */
7
- export default class FormMessage extends OutputMessage {
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
14
  data: any;
9
15
  schema: any;
10
16
  /**
@@ -25,4 +31,4 @@ export default class FormMessage extends OutputMessage {
25
31
  errors: any;
26
32
  };
27
33
  }
28
- import OutputMessage from "../Message/OutputMessage.js";
34
+ import InputMessage from "../Message/InputMessage.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
  *
@@ -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";
@@ -27,7 +27,7 @@ export default class OutputMessage extends UIMessage {
27
27
  /** @type {number} */
28
28
  priority: number;
29
29
  /** @param {string[]|string} value */
30
- set content(arg: string[]);
30
+ set content(value: string[] | string);
31
31
  /** @returns {string[]} */
32
32
  get content(): string[];
33
33
  /** @returns {number} */
@@ -22,6 +22,6 @@ export default class UIStream {
22
22
  * @param {Function} [onComplete] - Called with (item) when done.
23
23
  * @returns {Promise<void>}
24
24
  */
25
- static process(signal: AbortSignal, generator: Function, onProgress?: Function | undefined, onError?: Function | undefined, onComplete?: Function | undefined): Promise<void>;
25
+ static process(signal: AbortSignal, generator: Function, onProgress?: Function, onError?: Function, onComplete?: Function): Promise<void>;
26
26
  }
27
27
  import StreamEntry from "./StreamEntry.js";
@@ -21,7 +21,7 @@ export default class StreamEntry {
21
21
  done?: boolean | undefined;
22
22
  cancelled?: boolean | undefined;
23
23
  error?: string | undefined;
24
- } | undefined);
24
+ });
25
25
  /**
26
26
  * The value of the stream entry.
27
27
  * @type {any}
@@ -7,3 +7,4 @@ export { default as OutputMessage } from "./Message/OutputMessage.js";
7
7
  export { default as FormMessage } from "./Form/Message.js";
8
8
  export { default as FormInput } from "./Form/Input.js";
9
9
  export { default as UIForm } from "./Form/Form.js";
10
+ export { default as Error, CancelError } from "./Error/index.js";
package/types/index.d.ts CHANGED
@@ -18,3 +18,4 @@ import Model from "./Model/index.js";
18
18
  import Component from "./Component/index.js";
19
19
  import App from "./App/index.js";
20
20
  export { Frame, FrameProps, Locale, StdIn, StdOut, View, RenderOptions, Model, Component, App };
21
+ export { default as Error, CancelError } from "./core/Error/index.js";