@optique/discover 1.2.0-dev.2252 → 1.2.0-dev.2255

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.
@@ -1,139 +0,0 @@
1
- import { CommandOptions } from "@optique/core/primitives";
2
- import { Mode, Parser } from "@optique/core/parser";
3
-
4
- //#region src/command.d.ts
5
- declare const commandBrand: unique symbol;
6
- /**
7
- * Metadata shown for a discovered command.
8
- *
9
- * This uses the same shape as Optique's `command()` options so discovered
10
- * commands can provide descriptions, usage overrides, visibility, and custom
11
- * command-level errors.
12
- *
13
- * @since 1.1.0
14
- */
15
- type CommandMetadata = CommandOptions;
16
- /**
17
- * Command path used by static command registration.
18
- *
19
- * An empty path represents the root command.
20
- *
21
- * @since 1.1.0
22
- */
23
- type CommandPath = readonly string[];
24
- /**
25
- * Input accepted by {@link defineCommand}.
26
- *
27
- * @template M The mode of the command parser.
28
- * @template T The parsed value passed to the command handler.
29
- * @since 1.1.0
30
- */
31
- interface CommandDefinition<M extends Mode, T> {
32
- /**
33
- * Command path used when commands are passed directly to `runProgram()`.
34
- * Use an empty path (`[]`) to register the root command.
35
- *
36
- * File-based discovery derives the command path from the file name and uses
37
- * this field only to validate that the declared path matches.
38
- */
39
- readonly path?: CommandPath;
40
- /**
41
- * Parser for this command's command-specific arguments and options.
42
- */
43
- readonly parser: Parser<M, T, unknown>;
44
- /**
45
- * Metadata used in help output and shell completion.
46
- */
47
- readonly metadata?: CommandMetadata;
48
- /**
49
- * Handles the parsed command value.
50
- *
51
- * @param value Parsed command value.
52
- * @returns Nothing, or a promise that resolves when command handling
53
- * completes.
54
- */
55
- readonly handler: (value: T) => void | Promise<void>;
56
- }
57
- /**
58
- * A discovered command module definition.
59
- *
60
- * @template M The mode of the command parser.
61
- * @template T The parsed value passed to the command handler.
62
- * @since 1.1.0
63
- */
64
- interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
65
- /**
66
- * Internal marker used to validate discovered modules.
67
- *
68
- * @internal
69
- */
70
- readonly [commandBrand]: true;
71
- }
72
- /**
73
- * A command that declares its own command path.
74
- *
75
- * Static `runProgram({ commands })` registration accepts this shape.
76
- *
77
- * @template M The mode of the command parser.
78
- * @template T The parsed value passed to the command handler.
79
- * @since 1.1.0
80
- */
81
- interface StaticCommand<M extends Mode, T> extends Command<M, T> {
82
- /**
83
- * Command path used by static command registration.
84
- */
85
- readonly path: CommandPath;
86
- }
87
- /**
88
- * A command with its handler value type erased.
89
- *
90
- * This type is used by discovery APIs that collect commands with different
91
- * parsed value types. The handler cannot be called directly without first
92
- * recovering the parser's value type.
93
- *
94
- * @since 1.1.0
95
- */
96
- type AnyCommand = Omit<Command<Mode, unknown>, "handler"> & {
97
- /**
98
- * Erased command handler.
99
- */
100
- readonly handler: (value: never) => void | Promise<void>;
101
- };
102
- /**
103
- * A statically registered command with its handler value type erased.
104
- *
105
- * @since 1.1.0
106
- */
107
- type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
108
- /**
109
- * Erased command handler.
110
- */
111
- readonly handler: (value: never) => void | Promise<void>;
112
- };
113
- /**
114
- * Defines a command module for `@optique/discover`.
115
- *
116
- * This helper returns its argument unchanged while preserving parser value
117
- * inference for the handler callback.
118
- *
119
- * @template M The mode of the command parser.
120
- * @template T The parsed value passed to the command handler.
121
- * @param command The command definition.
122
- * @returns The same command definition with inferred types.
123
- * @throws {TypeError} If the parser, path, or handler is missing or malformed.
124
- * @since 1.1.0
125
- */
126
- declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T> & {
127
- readonly path: CommandPath;
128
- }): StaticCommand<M, T>;
129
- declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T>): Command<M, T>;
130
- /**
131
- * Returns whether a value is a command created by {@link defineCommand}.
132
- *
133
- * @param value The value to inspect.
134
- * @returns `true` when the value is a discovered command definition.
135
- * @since 1.1.0
136
- */
137
- declare function isCommand(value: unknown): value is AnyCommand;
138
- //#endregion
139
- export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, StaticCommand, defineCommand, isCommand };
@@ -1,139 +0,0 @@
1
- import { CommandOptions } from "@optique/core/primitives";
2
- import { Mode, Parser } from "@optique/core/parser";
3
-
4
- //#region src/command.d.ts
5
- declare const commandBrand: unique symbol;
6
- /**
7
- * Metadata shown for a discovered command.
8
- *
9
- * This uses the same shape as Optique's `command()` options so discovered
10
- * commands can provide descriptions, usage overrides, visibility, and custom
11
- * command-level errors.
12
- *
13
- * @since 1.1.0
14
- */
15
- type CommandMetadata = CommandOptions;
16
- /**
17
- * Command path used by static command registration.
18
- *
19
- * An empty path represents the root command.
20
- *
21
- * @since 1.1.0
22
- */
23
- type CommandPath = readonly string[];
24
- /**
25
- * Input accepted by {@link defineCommand}.
26
- *
27
- * @template M The mode of the command parser.
28
- * @template T The parsed value passed to the command handler.
29
- * @since 1.1.0
30
- */
31
- interface CommandDefinition<M extends Mode, T> {
32
- /**
33
- * Command path used when commands are passed directly to `runProgram()`.
34
- * Use an empty path (`[]`) to register the root command.
35
- *
36
- * File-based discovery derives the command path from the file name and uses
37
- * this field only to validate that the declared path matches.
38
- */
39
- readonly path?: CommandPath;
40
- /**
41
- * Parser for this command's command-specific arguments and options.
42
- */
43
- readonly parser: Parser<M, T, unknown>;
44
- /**
45
- * Metadata used in help output and shell completion.
46
- */
47
- readonly metadata?: CommandMetadata;
48
- /**
49
- * Handles the parsed command value.
50
- *
51
- * @param value Parsed command value.
52
- * @returns Nothing, or a promise that resolves when command handling
53
- * completes.
54
- */
55
- readonly handler: (value: T) => void | Promise<void>;
56
- }
57
- /**
58
- * A discovered command module definition.
59
- *
60
- * @template M The mode of the command parser.
61
- * @template T The parsed value passed to the command handler.
62
- * @since 1.1.0
63
- */
64
- interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
65
- /**
66
- * Internal marker used to validate discovered modules.
67
- *
68
- * @internal
69
- */
70
- readonly [commandBrand]: true;
71
- }
72
- /**
73
- * A command that declares its own command path.
74
- *
75
- * Static `runProgram({ commands })` registration accepts this shape.
76
- *
77
- * @template M The mode of the command parser.
78
- * @template T The parsed value passed to the command handler.
79
- * @since 1.1.0
80
- */
81
- interface StaticCommand<M extends Mode, T> extends Command<M, T> {
82
- /**
83
- * Command path used by static command registration.
84
- */
85
- readonly path: CommandPath;
86
- }
87
- /**
88
- * A command with its handler value type erased.
89
- *
90
- * This type is used by discovery APIs that collect commands with different
91
- * parsed value types. The handler cannot be called directly without first
92
- * recovering the parser's value type.
93
- *
94
- * @since 1.1.0
95
- */
96
- type AnyCommand = Omit<Command<Mode, unknown>, "handler"> & {
97
- /**
98
- * Erased command handler.
99
- */
100
- readonly handler: (value: never) => void | Promise<void>;
101
- };
102
- /**
103
- * A statically registered command with its handler value type erased.
104
- *
105
- * @since 1.1.0
106
- */
107
- type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
108
- /**
109
- * Erased command handler.
110
- */
111
- readonly handler: (value: never) => void | Promise<void>;
112
- };
113
- /**
114
- * Defines a command module for `@optique/discover`.
115
- *
116
- * This helper returns its argument unchanged while preserving parser value
117
- * inference for the handler callback.
118
- *
119
- * @template M The mode of the command parser.
120
- * @template T The parsed value passed to the command handler.
121
- * @param command The command definition.
122
- * @returns The same command definition with inferred types.
123
- * @throws {TypeError} If the parser, path, or handler is missing or malformed.
124
- * @since 1.1.0
125
- */
126
- declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T> & {
127
- readonly path: CommandPath;
128
- }): StaticCommand<M, T>;
129
- declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T>): Command<M, T>;
130
- /**
131
- * Returns whether a value is a command created by {@link defineCommand}.
132
- *
133
- * @param value The value to inspect.
134
- * @returns `true` when the value is a discovered command definition.
135
- * @since 1.1.0
136
- */
137
- declare function isCommand(value: unknown): value is AnyCommand;
138
- //#endregion
139
- export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, StaticCommand, defineCommand, isCommand };