@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.
- package/README.md +18 -20
- package/package.json +15 -16
- package/src/App/Core/UI.js +0 -46
- package/src/App/Core/Widget.js +4 -6
- package/src/App/User/Command/Message.js +23 -37
- package/src/App/User/Command/index.js +3 -8
- package/src/App/User/UserApp.js +30 -10
- package/src/README.md.js +33 -33
- package/src/StdIn.js +12 -13
- package/src/View/View.js +5 -5
- package/src/core/Form/Form.js +8 -6
- package/src/core/Form/Input.js +1 -1
- package/src/core/Form/Message.js +6 -5
- package/src/core/InputAdapter.js +2 -2
- package/src/core/Message/Message.js +109 -19
- package/src/core/Message/OutputMessage.js +7 -7
- package/src/core/Message/index.js +3 -4
- package/src/core/Stream.js +10 -10
- package/src/core/UiAdapter.js +189 -0
- package/src/core/index.js +3 -6
- package/src/index.js +4 -4
- package/types/App/Core/UI.d.ts +0 -10
- package/types/App/Core/Widget.d.ts +6 -7
- package/types/App/User/Command/Message.d.ts +15 -28
- package/types/App/User/Command/index.d.ts +3 -4
- package/types/App/User/UserApp.d.ts +14 -7
- package/types/StdIn.d.ts +13 -13
- package/types/View/View.d.ts +6 -6
- package/types/core/Form/Form.d.ts +2 -5
- package/types/core/Form/Input.d.ts +1 -1
- package/types/core/Form/Message.d.ts +5 -10
- package/types/core/Intent.d.ts +91 -0
- package/types/core/Message/Message.d.ts +58 -15
- package/types/core/Message/OutputMessage.d.ts +3 -3
- package/types/core/Message/index.d.ts +3 -4
- package/types/core/Stream.d.ts +5 -4
- package/types/core/UiAdapter.d.ts +104 -0
- package/types/core/index.d.ts +2 -3
- package/types/index.d.ts +4 -4
- package/src/App/User/Command/Options.js +0 -48
- package/src/core/Message/InputMessage.js +0 -119
|
@@ -1,29 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
2
|
-
export default _default;
|
|
1
|
+
export default CommandMessage;
|
|
3
2
|
import CommandMessage from "./Message.js";
|
|
4
|
-
import
|
|
5
|
-
export { CommandMessage,
|
|
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
|
-
|
|
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 {
|
|
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:
|
|
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 {
|
|
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:
|
|
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
|
|
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
|
-
|
|
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 {
|
|
19
|
+
* @param {UiMessage[]} [props.stream=[]] - Initial input stream
|
|
21
20
|
*/
|
|
22
21
|
constructor(props?: {
|
|
23
22
|
processor?: Processor | undefined;
|
|
24
|
-
stream?:
|
|
23
|
+
stream?: UiMessage[] | undefined;
|
|
25
24
|
});
|
|
26
|
-
/** @type {
|
|
27
|
-
stream:
|
|
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<
|
|
42
|
+
* @returns {Promise<UiMessage>} Next input message
|
|
44
43
|
*/
|
|
45
|
-
read(): Promise<
|
|
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
|
|
54
|
-
* @param {
|
|
55
|
-
* @returns {
|
|
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:
|
|
56
|
+
decode(message: UiMessage | string[] | any): UiMessage;
|
|
58
57
|
}
|
|
59
58
|
import EventProcessor from "@nan0web/event/oop";
|
|
60
|
-
import
|
|
59
|
+
import { UiMessage } from "./core/index.js";
|
|
61
60
|
declare class Processor extends EventProcessor {
|
|
62
61
|
}
|
|
62
|
+
export {};
|
package/types/View/View.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {Object} ComponentFn
|
|
3
3
|
* @property {string} name
|
|
4
|
-
* @property {(input:
|
|
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 {
|
|
100
|
-
* @returns {Promise<
|
|
99
|
+
* @param {UiMessage} input
|
|
100
|
+
* @returns {Promise<UiMessage | null>}
|
|
101
101
|
*/
|
|
102
|
-
ask(input:
|
|
102
|
+
ask(input: UiMessage): Promise<UiMessage | null>;
|
|
103
103
|
}
|
|
104
104
|
export type ComponentFn = {
|
|
105
105
|
name: string;
|
|
106
|
-
ask: (input:
|
|
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
|
|
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 {
|
|
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 {
|
|
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
|
|
2
|
+
* FormMessage – specialized UiMessage for forms.
|
|
3
|
+
* It carries form-specific data and schema for validation.
|
|
3
4
|
*
|
|
4
5
|
* @class FormMessage
|
|
5
|
-
* @extends
|
|
6
|
+
* @extends UiMessage
|
|
6
7
|
*/
|
|
7
|
-
export default class FormMessage extends
|
|
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
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
6
|
-
*
|
|
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
|
-
|
|
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
|
|
43
|
+
* Creates a UiMessage instance from plain data.
|
|
22
44
|
*
|
|
23
45
|
* @param {Object} data - Message data.
|
|
24
|
-
* @returns {
|
|
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
|
|
56
|
+
static parseBody(input: any, BodyClass: Function): any;
|
|
27
57
|
/**
|
|
28
|
-
* Creates a
|
|
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
|
-
*
|
|
68
|
+
* Validates the message body against its schema.
|
|
39
69
|
*
|
|
40
|
-
*
|
|
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
|
-
|
|
77
|
+
validate(body?: any): Map<string, string>;
|
|
43
78
|
/**
|
|
44
|
-
* Checks
|
|
79
|
+
* Checks if the message type is valid.
|
|
45
80
|
*
|
|
46
81
|
* @returns {boolean}
|
|
47
82
|
*/
|
|
48
|
-
|
|
83
|
+
isValidType(): boolean;
|
|
49
84
|
}
|
|
50
|
-
|
|
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
|
|
5
|
+
* @extends UiMessage
|
|
6
6
|
*/
|
|
7
|
-
export default class OutputMessage extends
|
|
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
|
|
53
|
+
import UiMessage from "./Message.js";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export default
|
|
2
|
-
import
|
|
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 {
|
|
4
|
+
export { UiMessage, OutputMessage };
|
package/types/core/Stream.d.ts
CHANGED
|
@@ -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
|
|
17
|
+
* Runs an async generator with progress callbacks and abort handling.
|
|
17
18
|
*
|
|
18
19
|
* @param {AbortSignal} signal - Abort signal.
|
|
19
|
-
* @param {
|
|
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,
|
|
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";
|
package/types/core/index.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
8
|
-
export { default as
|
|
9
|
-
export { default as
|
|
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";
|