@optique/discover 1.2.0-dev.2330 → 1.2.0-dev.2333
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/dist/cli.cjs +3 -3
- package/dist/cli.js +3 -3
- package/dist/{command-Dvg452tU.d.cts → command-BaFBKA4c.d.ts} +167 -19
- package/dist/{command-egqHCvDL.d.ts → command-BtjFShKT.d.cts} +167 -19
- package/dist/command.d.cts +2 -2
- package/dist/command.d.ts +2 -2
- package/dist/{generator-Dc9I4tTs.cjs → generator-4mV9w1F0.cjs} +1 -1
- package/dist/{generator-wZHULCZH.js → generator-CJiusCJb.js} +1 -1
- package/dist/generator.cjs +2 -2
- package/dist/generator.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +37 -11
- package/dist/index.d.ts +37 -11
- package/dist/index.js +1 -1
- package/dist/{src-CPtrcNkd.cjs → src-Bb2ONs5m.cjs} +3 -0
- package/dist/{src-CCeOMJRj.js → src-Ddp18zFp.js} +3 -0
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
3
3
|
require('./command-C-NgG0KJ.cjs');
|
|
4
|
-
require('./src-
|
|
5
|
-
const require_generator = require('./generator-
|
|
4
|
+
require('./src-Bb2ONs5m.cjs');
|
|
5
|
+
const require_generator = require('./generator-4mV9w1F0.cjs');
|
|
6
6
|
const require_main_check = require('./main-check-CwunSNpK.cjs');
|
|
7
7
|
const __optique_core_constructs = require_chunk.__toESM(require("@optique/core/constructs"));
|
|
8
8
|
const __optique_core_message = require_chunk.__toESM(require("@optique/core/message"));
|
|
@@ -15,7 +15,7 @@ const node_process = require_chunk.__toESM(require("node:process"));
|
|
|
15
15
|
|
|
16
16
|
//#region deno.json
|
|
17
17
|
var name = "@optique/discover";
|
|
18
|
-
var version = "1.2.0-dev.
|
|
18
|
+
var version = "1.2.0-dev.2333+f7f47e8b";
|
|
19
19
|
var license = "MIT";
|
|
20
20
|
var exports$1 = {
|
|
21
21
|
".": "./src/index.ts",
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "./command-9sgrJtwh.js";
|
|
3
|
-
import "./src-
|
|
4
|
-
import { watchCommandsModule, writeCommandsModule } from "./generator-
|
|
3
|
+
import "./src-Ddp18zFp.js";
|
|
4
|
+
import { watchCommandsModule, writeCommandsModule } from "./generator-CJiusCJb.js";
|
|
5
5
|
import { isMainModuleUrl } from "./main-check-mMnKfUZs.js";
|
|
6
6
|
import { object } from "@optique/core/constructs";
|
|
7
7
|
import { message } from "@optique/core/message";
|
|
@@ -14,7 +14,7 @@ import process from "node:process";
|
|
|
14
14
|
|
|
15
15
|
//#region deno.json
|
|
16
16
|
var name = "@optique/discover";
|
|
17
|
-
var version = "1.2.0-dev.
|
|
17
|
+
var version = "1.2.0-dev.2333+f7f47e8b";
|
|
18
18
|
var license = "MIT";
|
|
19
19
|
var exports = {
|
|
20
20
|
".": "./src/index.ts",
|
|
@@ -30,14 +30,15 @@ type CommandPath = readonly string[];
|
|
|
30
30
|
* {@link ProgramHooks.afterEach} and {@link ProgramHooks.onError} hooks. This
|
|
31
31
|
* threads handler-time resources without global state.
|
|
32
32
|
*
|
|
33
|
+
* @template R The caller-defined resource stored in the context.
|
|
33
34
|
* @since 1.2.0
|
|
34
35
|
*/
|
|
35
|
-
interface ProgramHookContext {
|
|
36
|
+
interface ProgramHookContext<R = unknown> {
|
|
36
37
|
/**
|
|
37
38
|
* Caller-defined resource. Common shapes include a database pool, a logger
|
|
38
39
|
* scope, or a tracing span.
|
|
39
40
|
*/
|
|
40
|
-
readonly resource?:
|
|
41
|
+
readonly resource?: R;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* The parsed command selected by a discovered command parser.
|
|
@@ -94,9 +95,10 @@ interface ProgramInvocation {
|
|
|
94
95
|
* program.onError ← command.onError ← on failure
|
|
95
96
|
* ```
|
|
96
97
|
*
|
|
98
|
+
* @template R The resource returned by `beforeEach` and passed to later hooks.
|
|
97
99
|
* @since 1.2.0
|
|
98
100
|
*/
|
|
99
|
-
interface ProgramHooks {
|
|
101
|
+
interface ProgramHooks<R = unknown> {
|
|
100
102
|
/**
|
|
101
103
|
* Called before the command handler runs, receiving the matched command, its
|
|
102
104
|
* resolved {@link ProgramInvocation.path}, the parsed value, and the handler
|
|
@@ -112,7 +114,7 @@ interface ProgramHooks {
|
|
|
112
114
|
* promise (or a thrown error) aborts the command before the handler runs and
|
|
113
115
|
* invokes {@link onError}.
|
|
114
116
|
*/
|
|
115
|
-
readonly beforeEach?: (invocation: ProgramInvocation) => ProgramHookContext | null | void | Promise<ProgramHookContext | null | void>;
|
|
117
|
+
readonly beforeEach?: (invocation: ProgramInvocation) => ProgramHookContext<R> | null | void | Promise<ProgramHookContext<R> | null | void>;
|
|
116
118
|
/**
|
|
117
119
|
* Called after the handler returns successfully, receiving the context from
|
|
118
120
|
* {@link beforeEach} (or an empty object when no `beforeEach` ran) and the
|
|
@@ -122,7 +124,7 @@ interface ProgramHooks {
|
|
|
122
124
|
* throws or rejects, the dispatcher treats it as a handler failure and
|
|
123
125
|
* invokes {@link onError} with the thrown error.
|
|
124
126
|
*/
|
|
125
|
-
readonly afterEach?: (context: ProgramHookContext
|
|
127
|
+
readonly afterEach?: (context: ProgramHookContext<R>, result: unknown) => void | Promise<void>;
|
|
126
128
|
/**
|
|
127
129
|
* Called when the handler (or {@link beforeEach}/{@link afterEach}) throws or
|
|
128
130
|
* rejects, receiving the context from {@link beforeEach} (or an empty object)
|
|
@@ -135,16 +137,33 @@ interface ProgramHooks {
|
|
|
135
137
|
*
|
|
136
138
|
* Returning a promise is supported; the dispatcher awaits it.
|
|
137
139
|
*/
|
|
138
|
-
readonly onError?: (context: ProgramHookContext
|
|
140
|
+
readonly onError?: (context: ProgramHookContext<R>, error: unknown) => void | Promise<void>;
|
|
139
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Lifecycle hooks that always create their own command context.
|
|
144
|
+
*
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
type ProgramHooksWithBeforeEach<R> = ProgramHooks<R> & {
|
|
148
|
+
readonly beforeEach: NonNullable<ProgramHooks<R>["beforeEach"]>;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Lifecycle hooks that do not replace the program-level command context.
|
|
152
|
+
*
|
|
153
|
+
* @internal
|
|
154
|
+
*/
|
|
155
|
+
type ProgramHooksWithoutBeforeEach<R> = Omit<ProgramHooks<R>, "beforeEach"> & {
|
|
156
|
+
readonly beforeEach?: undefined;
|
|
157
|
+
};
|
|
140
158
|
/**
|
|
141
159
|
* Input accepted by {@link defineCommand}.
|
|
142
160
|
*
|
|
143
161
|
* @template M The mode of the command parser.
|
|
144
162
|
* @template T The parsed value passed to the command handler.
|
|
163
|
+
* @template R The resource made available to lifecycle hooks and the handler.
|
|
145
164
|
* @since 1.1.0
|
|
146
165
|
*/
|
|
147
|
-
interface CommandDefinition<M extends Mode, T> {
|
|
166
|
+
interface CommandDefinition<M extends Mode, T, R = unknown> {
|
|
148
167
|
/**
|
|
149
168
|
* Command path used when commands are passed directly to `runProgram()`.
|
|
150
169
|
* Use an empty path (`[]`) to register the root command.
|
|
@@ -172,7 +191,7 @@ interface CommandDefinition<M extends Mode, T> {
|
|
|
172
191
|
*
|
|
173
192
|
* @since 1.2.0
|
|
174
193
|
*/
|
|
175
|
-
readonly hooks?: ProgramHooks
|
|
194
|
+
readonly hooks?: ProgramHooks<R>;
|
|
176
195
|
/**
|
|
177
196
|
* Handles the parsed command value.
|
|
178
197
|
*
|
|
@@ -185,16 +204,17 @@ interface CommandDefinition<M extends Mode, T> {
|
|
|
185
204
|
* @returns Nothing, or a promise that resolves when command handling
|
|
186
205
|
* completes.
|
|
187
206
|
*/
|
|
188
|
-
readonly handler: (value: T, context?: ProgramHookContext) => void | Promise<void>;
|
|
207
|
+
readonly handler: (value: T, context?: ProgramHookContext<R>) => void | Promise<void>;
|
|
189
208
|
}
|
|
190
209
|
/**
|
|
191
210
|
* A discovered command module definition.
|
|
192
211
|
*
|
|
193
212
|
* @template M The mode of the command parser.
|
|
194
213
|
* @template T The parsed value passed to the command handler.
|
|
214
|
+
* @template R The resource made available to lifecycle hooks and the handler.
|
|
195
215
|
* @since 1.1.0
|
|
196
216
|
*/
|
|
197
|
-
interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
|
|
217
|
+
interface Command<M extends Mode, T, R = unknown> extends CommandDefinition<M, T, R> {
|
|
198
218
|
/**
|
|
199
219
|
* Internal marker used to validate discovered modules.
|
|
200
220
|
*
|
|
@@ -209,14 +229,61 @@ interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
|
|
|
209
229
|
*
|
|
210
230
|
* @template M The mode of the command parser.
|
|
211
231
|
* @template T The parsed value passed to the command handler.
|
|
232
|
+
* @template R The resource made available to lifecycle hooks and the handler.
|
|
212
233
|
* @since 1.1.0
|
|
213
234
|
*/
|
|
214
|
-
interface StaticCommand<M extends Mode, T> extends Command<M, T> {
|
|
235
|
+
interface StaticCommand<M extends Mode, T, R = unknown> extends Command<M, T, R> {
|
|
215
236
|
/**
|
|
216
237
|
* Command path used by static command registration.
|
|
217
238
|
*/
|
|
218
239
|
readonly path: CommandPath;
|
|
219
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* A command whose hooks always create their own command context.
|
|
243
|
+
*
|
|
244
|
+
* @internal
|
|
245
|
+
*/
|
|
246
|
+
type CommandWithBeforeEach<M extends Mode, T, R> = Command<M, T, R> & {
|
|
247
|
+
readonly hooks: ProgramHooksWithBeforeEach<R>;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* A static command whose hooks always create their own command context.
|
|
251
|
+
*
|
|
252
|
+
* @internal
|
|
253
|
+
*/
|
|
254
|
+
type StaticCommandWithBeforeEach<M extends Mode, T, R> = StaticCommand<M, T, R> & CommandWithBeforeEach<M, T, R>;
|
|
255
|
+
/**
|
|
256
|
+
* A command that does not create its own command context.
|
|
257
|
+
*
|
|
258
|
+
* @internal
|
|
259
|
+
*/
|
|
260
|
+
type CommandWithoutBeforeEach<M extends Mode, T, R> = Omit<Command<M, T, R>, "hooks"> & {
|
|
261
|
+
readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* A static command that does not create its own command context.
|
|
265
|
+
*
|
|
266
|
+
* @internal
|
|
267
|
+
*/
|
|
268
|
+
type StaticCommandWithoutBeforeEach<M extends Mode, T, R> = Omit<StaticCommand<M, T, R>, "hooks"> & CommandWithoutBeforeEach<M, T, R>;
|
|
269
|
+
/**
|
|
270
|
+
* Lifecycle hooks whose caller-defined resource type has been erased.
|
|
271
|
+
*
|
|
272
|
+
* @internal
|
|
273
|
+
*/
|
|
274
|
+
interface ErasedProgramHooks {
|
|
275
|
+
readonly beforeEach?: ProgramHooks<unknown>["beforeEach"];
|
|
276
|
+
readonly afterEach?: ProgramHooks<never>["afterEach"];
|
|
277
|
+
readonly onError?: ProgramHooks<never>["onError"];
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Erased lifecycle hooks that always create their own command context.
|
|
281
|
+
*
|
|
282
|
+
* @internal
|
|
283
|
+
*/
|
|
284
|
+
interface ErasedProgramHooksWithBeforeEach extends ErasedProgramHooks {
|
|
285
|
+
readonly beforeEach: NonNullable<ErasedProgramHooks["beforeEach"]>;
|
|
286
|
+
}
|
|
220
287
|
/**
|
|
221
288
|
* A command with its handler value type erased.
|
|
222
289
|
*
|
|
@@ -226,23 +293,87 @@ interface StaticCommand<M extends Mode, T> extends Command<M, T> {
|
|
|
226
293
|
*
|
|
227
294
|
* @since 1.1.0
|
|
228
295
|
*/
|
|
229
|
-
type AnyCommand = Omit<Command<Mode, unknown>, "handler"> & {
|
|
296
|
+
type AnyCommand = Omit<Command<Mode, unknown>, "handler" | "hooks"> & {
|
|
297
|
+
/**
|
|
298
|
+
* Lifecycle hooks with their caller-defined resource type erased.
|
|
299
|
+
*/
|
|
300
|
+
readonly hooks?: ErasedProgramHooks;
|
|
230
301
|
/**
|
|
231
302
|
* Erased command handler.
|
|
232
303
|
*/
|
|
233
|
-
readonly handler: (value: never, context?: ProgramHookContext) => void | Promise<void>;
|
|
304
|
+
readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
|
|
234
305
|
};
|
|
235
306
|
/**
|
|
236
307
|
* A statically registered command with its handler value type erased.
|
|
237
308
|
*
|
|
238
309
|
* @since 1.1.0
|
|
239
310
|
*/
|
|
240
|
-
type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
|
|
311
|
+
type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler" | "hooks"> & {
|
|
312
|
+
/**
|
|
313
|
+
* Lifecycle hooks with their caller-defined resource type erased.
|
|
314
|
+
*/
|
|
315
|
+
readonly hooks?: ErasedProgramHooks;
|
|
241
316
|
/**
|
|
242
317
|
* Erased command handler.
|
|
243
318
|
*/
|
|
244
|
-
readonly handler: (value: never, context?: ProgramHookContext) => void | Promise<void>;
|
|
319
|
+
readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* A type-erased command whose handler consumes a program-level resource.
|
|
323
|
+
*
|
|
324
|
+
* @internal
|
|
325
|
+
*/
|
|
326
|
+
type ProgramResourceCommand<R> = Omit<Command<Mode, unknown, R>, "handler"> & {
|
|
327
|
+
readonly handler: (value: never, context?: ProgramHookContext<R>) => void | Promise<void>;
|
|
245
328
|
};
|
|
329
|
+
/**
|
|
330
|
+
* A type-erased command that always creates its own command context.
|
|
331
|
+
*
|
|
332
|
+
* @internal
|
|
333
|
+
*/
|
|
334
|
+
type OwnResourceCommand = Omit<AnyCommand, "hooks"> & {
|
|
335
|
+
readonly hooks: ErasedProgramHooksWithBeforeEach;
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* A type-erased static command whose handler consumes a program-level
|
|
339
|
+
* resource.
|
|
340
|
+
*
|
|
341
|
+
* @internal
|
|
342
|
+
*/
|
|
343
|
+
type ProgramResourceStaticCommand<R> = Omit<StaticCommand<Mode, unknown, R>, "handler"> & {
|
|
344
|
+
readonly handler: (value: never, context?: ProgramHookContext<R>) => void | Promise<void>;
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* A type-erased static command that always creates its own command context.
|
|
348
|
+
*
|
|
349
|
+
* @internal
|
|
350
|
+
*/
|
|
351
|
+
type OwnResourceStaticCommand = Omit<AnyStaticCommand, "hooks"> & {
|
|
352
|
+
readonly hooks: ErasedProgramHooksWithBeforeEach;
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* A command accepted by `runProgram()` with a program-level resource type.
|
|
356
|
+
*
|
|
357
|
+
* Commands without a command-level `beforeEach` must consume `R`. A command
|
|
358
|
+
* that always creates its own context may use a different resource type.
|
|
359
|
+
* Untyped calls retain the fully erased command shape for compatibility.
|
|
360
|
+
*
|
|
361
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
362
|
+
* @since 1.2.0
|
|
363
|
+
*/
|
|
364
|
+
type RunProgramCommand<R = unknown> = unknown extends R ? AnyCommand : ProgramResourceCommand<R> | OwnResourceCommand;
|
|
365
|
+
/**
|
|
366
|
+
* A static command accepted by `runProgram()` with a program-level resource
|
|
367
|
+
* type.
|
|
368
|
+
*
|
|
369
|
+
* Commands without a command-level `beforeEach` must consume `R`. A command
|
|
370
|
+
* that always creates its own context may use a different resource type.
|
|
371
|
+
* Untyped calls retain the fully erased command shape for compatibility.
|
|
372
|
+
*
|
|
373
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
374
|
+
* @since 1.2.0
|
|
375
|
+
*/
|
|
376
|
+
type RunProgramStaticCommand<R = unknown> = unknown extends R ? AnyStaticCommand : ProgramResourceStaticCommand<R> | OwnResourceStaticCommand;
|
|
246
377
|
/**
|
|
247
378
|
* Defines a command module for `@optique/discover`.
|
|
248
379
|
*
|
|
@@ -251,16 +382,33 @@ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
|
|
|
251
382
|
*
|
|
252
383
|
* @template M The mode of the command parser.
|
|
253
384
|
* @template T The parsed value passed to the command handler.
|
|
385
|
+
* @template R The resource made available to lifecycle hooks and the handler.
|
|
254
386
|
* @param command The command definition.
|
|
255
387
|
* @returns The same command definition with inferred types.
|
|
256
388
|
* @throws {TypeError} If the parser, path, handler, or hooks are missing or
|
|
257
389
|
* malformed.
|
|
258
390
|
* @since 1.1.0
|
|
259
391
|
*/
|
|
260
|
-
declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T> & {
|
|
392
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
|
|
393
|
+
readonly path: CommandPath;
|
|
394
|
+
} & {
|
|
395
|
+
readonly hooks: ProgramHooksWithBeforeEach<R>;
|
|
396
|
+
}): StaticCommandWithBeforeEach<M, T, R>;
|
|
397
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: Omit<CommandDefinition<M, T, R>, "hooks"> & {
|
|
398
|
+
readonly path: CommandPath;
|
|
399
|
+
} & {
|
|
400
|
+
readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
|
|
401
|
+
}): StaticCommandWithoutBeforeEach<M, T, R>;
|
|
402
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
|
|
403
|
+
readonly hooks: ProgramHooksWithBeforeEach<R>;
|
|
404
|
+
}): CommandWithBeforeEach<M, T, R>;
|
|
405
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: Omit<CommandDefinition<M, T, R>, "hooks"> & {
|
|
406
|
+
readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
|
|
407
|
+
}): CommandWithoutBeforeEach<M, T, R>;
|
|
408
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
|
|
261
409
|
readonly path: CommandPath;
|
|
262
|
-
}): StaticCommand<M, T>;
|
|
263
|
-
declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T>): Command<M, T>;
|
|
410
|
+
}): StaticCommand<M, T, R>;
|
|
411
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R>): Command<M, T, R>;
|
|
264
412
|
/**
|
|
265
413
|
* Returns whether a value is a command created by {@link defineCommand}.
|
|
266
414
|
*
|
|
@@ -282,4 +430,4 @@ declare function isCommand(value: unknown): value is AnyCommand;
|
|
|
282
430
|
*/
|
|
283
431
|
declare function validateHooks(hooks: unknown, scope: "Command" | "Program"): asserts hooks is ProgramHooks;
|
|
284
432
|
//#endregion
|
|
285
|
-
export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks };
|
|
433
|
+
export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks };
|
|
@@ -30,14 +30,15 @@ type CommandPath = readonly string[];
|
|
|
30
30
|
* {@link ProgramHooks.afterEach} and {@link ProgramHooks.onError} hooks. This
|
|
31
31
|
* threads handler-time resources without global state.
|
|
32
32
|
*
|
|
33
|
+
* @template R The caller-defined resource stored in the context.
|
|
33
34
|
* @since 1.2.0
|
|
34
35
|
*/
|
|
35
|
-
interface ProgramHookContext {
|
|
36
|
+
interface ProgramHookContext<R = unknown> {
|
|
36
37
|
/**
|
|
37
38
|
* Caller-defined resource. Common shapes include a database pool, a logger
|
|
38
39
|
* scope, or a tracing span.
|
|
39
40
|
*/
|
|
40
|
-
readonly resource?:
|
|
41
|
+
readonly resource?: R;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* The parsed command selected by a discovered command parser.
|
|
@@ -94,9 +95,10 @@ interface ProgramInvocation {
|
|
|
94
95
|
* program.onError ← command.onError ← on failure
|
|
95
96
|
* ```
|
|
96
97
|
*
|
|
98
|
+
* @template R The resource returned by `beforeEach` and passed to later hooks.
|
|
97
99
|
* @since 1.2.0
|
|
98
100
|
*/
|
|
99
|
-
interface ProgramHooks {
|
|
101
|
+
interface ProgramHooks<R = unknown> {
|
|
100
102
|
/**
|
|
101
103
|
* Called before the command handler runs, receiving the matched command, its
|
|
102
104
|
* resolved {@link ProgramInvocation.path}, the parsed value, and the handler
|
|
@@ -112,7 +114,7 @@ interface ProgramHooks {
|
|
|
112
114
|
* promise (or a thrown error) aborts the command before the handler runs and
|
|
113
115
|
* invokes {@link onError}.
|
|
114
116
|
*/
|
|
115
|
-
readonly beforeEach?: (invocation: ProgramInvocation) => ProgramHookContext | null | void | Promise<ProgramHookContext | null | void>;
|
|
117
|
+
readonly beforeEach?: (invocation: ProgramInvocation) => ProgramHookContext<R> | null | void | Promise<ProgramHookContext<R> | null | void>;
|
|
116
118
|
/**
|
|
117
119
|
* Called after the handler returns successfully, receiving the context from
|
|
118
120
|
* {@link beforeEach} (or an empty object when no `beforeEach` ran) and the
|
|
@@ -122,7 +124,7 @@ interface ProgramHooks {
|
|
|
122
124
|
* throws or rejects, the dispatcher treats it as a handler failure and
|
|
123
125
|
* invokes {@link onError} with the thrown error.
|
|
124
126
|
*/
|
|
125
|
-
readonly afterEach?: (context: ProgramHookContext
|
|
127
|
+
readonly afterEach?: (context: ProgramHookContext<R>, result: unknown) => void | Promise<void>;
|
|
126
128
|
/**
|
|
127
129
|
* Called when the handler (or {@link beforeEach}/{@link afterEach}) throws or
|
|
128
130
|
* rejects, receiving the context from {@link beforeEach} (or an empty object)
|
|
@@ -135,16 +137,33 @@ interface ProgramHooks {
|
|
|
135
137
|
*
|
|
136
138
|
* Returning a promise is supported; the dispatcher awaits it.
|
|
137
139
|
*/
|
|
138
|
-
readonly onError?: (context: ProgramHookContext
|
|
140
|
+
readonly onError?: (context: ProgramHookContext<R>, error: unknown) => void | Promise<void>;
|
|
139
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Lifecycle hooks that always create their own command context.
|
|
144
|
+
*
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
type ProgramHooksWithBeforeEach<R> = ProgramHooks<R> & {
|
|
148
|
+
readonly beforeEach: NonNullable<ProgramHooks<R>["beforeEach"]>;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Lifecycle hooks that do not replace the program-level command context.
|
|
152
|
+
*
|
|
153
|
+
* @internal
|
|
154
|
+
*/
|
|
155
|
+
type ProgramHooksWithoutBeforeEach<R> = Omit<ProgramHooks<R>, "beforeEach"> & {
|
|
156
|
+
readonly beforeEach?: undefined;
|
|
157
|
+
};
|
|
140
158
|
/**
|
|
141
159
|
* Input accepted by {@link defineCommand}.
|
|
142
160
|
*
|
|
143
161
|
* @template M The mode of the command parser.
|
|
144
162
|
* @template T The parsed value passed to the command handler.
|
|
163
|
+
* @template R The resource made available to lifecycle hooks and the handler.
|
|
145
164
|
* @since 1.1.0
|
|
146
165
|
*/
|
|
147
|
-
interface CommandDefinition<M extends Mode, T> {
|
|
166
|
+
interface CommandDefinition<M extends Mode, T, R = unknown> {
|
|
148
167
|
/**
|
|
149
168
|
* Command path used when commands are passed directly to `runProgram()`.
|
|
150
169
|
* Use an empty path (`[]`) to register the root command.
|
|
@@ -172,7 +191,7 @@ interface CommandDefinition<M extends Mode, T> {
|
|
|
172
191
|
*
|
|
173
192
|
* @since 1.2.0
|
|
174
193
|
*/
|
|
175
|
-
readonly hooks?: ProgramHooks
|
|
194
|
+
readonly hooks?: ProgramHooks<R>;
|
|
176
195
|
/**
|
|
177
196
|
* Handles the parsed command value.
|
|
178
197
|
*
|
|
@@ -185,16 +204,17 @@ interface CommandDefinition<M extends Mode, T> {
|
|
|
185
204
|
* @returns Nothing, or a promise that resolves when command handling
|
|
186
205
|
* completes.
|
|
187
206
|
*/
|
|
188
|
-
readonly handler: (value: T, context?: ProgramHookContext) => void | Promise<void>;
|
|
207
|
+
readonly handler: (value: T, context?: ProgramHookContext<R>) => void | Promise<void>;
|
|
189
208
|
}
|
|
190
209
|
/**
|
|
191
210
|
* A discovered command module definition.
|
|
192
211
|
*
|
|
193
212
|
* @template M The mode of the command parser.
|
|
194
213
|
* @template T The parsed value passed to the command handler.
|
|
214
|
+
* @template R The resource made available to lifecycle hooks and the handler.
|
|
195
215
|
* @since 1.1.0
|
|
196
216
|
*/
|
|
197
|
-
interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
|
|
217
|
+
interface Command<M extends Mode, T, R = unknown> extends CommandDefinition<M, T, R> {
|
|
198
218
|
/**
|
|
199
219
|
* Internal marker used to validate discovered modules.
|
|
200
220
|
*
|
|
@@ -209,14 +229,61 @@ interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
|
|
|
209
229
|
*
|
|
210
230
|
* @template M The mode of the command parser.
|
|
211
231
|
* @template T The parsed value passed to the command handler.
|
|
232
|
+
* @template R The resource made available to lifecycle hooks and the handler.
|
|
212
233
|
* @since 1.1.0
|
|
213
234
|
*/
|
|
214
|
-
interface StaticCommand<M extends Mode, T> extends Command<M, T> {
|
|
235
|
+
interface StaticCommand<M extends Mode, T, R = unknown> extends Command<M, T, R> {
|
|
215
236
|
/**
|
|
216
237
|
* Command path used by static command registration.
|
|
217
238
|
*/
|
|
218
239
|
readonly path: CommandPath;
|
|
219
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* A command whose hooks always create their own command context.
|
|
243
|
+
*
|
|
244
|
+
* @internal
|
|
245
|
+
*/
|
|
246
|
+
type CommandWithBeforeEach<M extends Mode, T, R> = Command<M, T, R> & {
|
|
247
|
+
readonly hooks: ProgramHooksWithBeforeEach<R>;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* A static command whose hooks always create their own command context.
|
|
251
|
+
*
|
|
252
|
+
* @internal
|
|
253
|
+
*/
|
|
254
|
+
type StaticCommandWithBeforeEach<M extends Mode, T, R> = StaticCommand<M, T, R> & CommandWithBeforeEach<M, T, R>;
|
|
255
|
+
/**
|
|
256
|
+
* A command that does not create its own command context.
|
|
257
|
+
*
|
|
258
|
+
* @internal
|
|
259
|
+
*/
|
|
260
|
+
type CommandWithoutBeforeEach<M extends Mode, T, R> = Omit<Command<M, T, R>, "hooks"> & {
|
|
261
|
+
readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* A static command that does not create its own command context.
|
|
265
|
+
*
|
|
266
|
+
* @internal
|
|
267
|
+
*/
|
|
268
|
+
type StaticCommandWithoutBeforeEach<M extends Mode, T, R> = Omit<StaticCommand<M, T, R>, "hooks"> & CommandWithoutBeforeEach<M, T, R>;
|
|
269
|
+
/**
|
|
270
|
+
* Lifecycle hooks whose caller-defined resource type has been erased.
|
|
271
|
+
*
|
|
272
|
+
* @internal
|
|
273
|
+
*/
|
|
274
|
+
interface ErasedProgramHooks {
|
|
275
|
+
readonly beforeEach?: ProgramHooks<unknown>["beforeEach"];
|
|
276
|
+
readonly afterEach?: ProgramHooks<never>["afterEach"];
|
|
277
|
+
readonly onError?: ProgramHooks<never>["onError"];
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Erased lifecycle hooks that always create their own command context.
|
|
281
|
+
*
|
|
282
|
+
* @internal
|
|
283
|
+
*/
|
|
284
|
+
interface ErasedProgramHooksWithBeforeEach extends ErasedProgramHooks {
|
|
285
|
+
readonly beforeEach: NonNullable<ErasedProgramHooks["beforeEach"]>;
|
|
286
|
+
}
|
|
220
287
|
/**
|
|
221
288
|
* A command with its handler value type erased.
|
|
222
289
|
*
|
|
@@ -226,23 +293,87 @@ interface StaticCommand<M extends Mode, T> extends Command<M, T> {
|
|
|
226
293
|
*
|
|
227
294
|
* @since 1.1.0
|
|
228
295
|
*/
|
|
229
|
-
type AnyCommand = Omit<Command<Mode, unknown>, "handler"> & {
|
|
296
|
+
type AnyCommand = Omit<Command<Mode, unknown>, "handler" | "hooks"> & {
|
|
297
|
+
/**
|
|
298
|
+
* Lifecycle hooks with their caller-defined resource type erased.
|
|
299
|
+
*/
|
|
300
|
+
readonly hooks?: ErasedProgramHooks;
|
|
230
301
|
/**
|
|
231
302
|
* Erased command handler.
|
|
232
303
|
*/
|
|
233
|
-
readonly handler: (value: never, context?: ProgramHookContext) => void | Promise<void>;
|
|
304
|
+
readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
|
|
234
305
|
};
|
|
235
306
|
/**
|
|
236
307
|
* A statically registered command with its handler value type erased.
|
|
237
308
|
*
|
|
238
309
|
* @since 1.1.0
|
|
239
310
|
*/
|
|
240
|
-
type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
|
|
311
|
+
type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler" | "hooks"> & {
|
|
312
|
+
/**
|
|
313
|
+
* Lifecycle hooks with their caller-defined resource type erased.
|
|
314
|
+
*/
|
|
315
|
+
readonly hooks?: ErasedProgramHooks;
|
|
241
316
|
/**
|
|
242
317
|
* Erased command handler.
|
|
243
318
|
*/
|
|
244
|
-
readonly handler: (value: never, context?: ProgramHookContext) => void | Promise<void>;
|
|
319
|
+
readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* A type-erased command whose handler consumes a program-level resource.
|
|
323
|
+
*
|
|
324
|
+
* @internal
|
|
325
|
+
*/
|
|
326
|
+
type ProgramResourceCommand<R> = Omit<Command<Mode, unknown, R>, "handler"> & {
|
|
327
|
+
readonly handler: (value: never, context?: ProgramHookContext<R>) => void | Promise<void>;
|
|
245
328
|
};
|
|
329
|
+
/**
|
|
330
|
+
* A type-erased command that always creates its own command context.
|
|
331
|
+
*
|
|
332
|
+
* @internal
|
|
333
|
+
*/
|
|
334
|
+
type OwnResourceCommand = Omit<AnyCommand, "hooks"> & {
|
|
335
|
+
readonly hooks: ErasedProgramHooksWithBeforeEach;
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* A type-erased static command whose handler consumes a program-level
|
|
339
|
+
* resource.
|
|
340
|
+
*
|
|
341
|
+
* @internal
|
|
342
|
+
*/
|
|
343
|
+
type ProgramResourceStaticCommand<R> = Omit<StaticCommand<Mode, unknown, R>, "handler"> & {
|
|
344
|
+
readonly handler: (value: never, context?: ProgramHookContext<R>) => void | Promise<void>;
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* A type-erased static command that always creates its own command context.
|
|
348
|
+
*
|
|
349
|
+
* @internal
|
|
350
|
+
*/
|
|
351
|
+
type OwnResourceStaticCommand = Omit<AnyStaticCommand, "hooks"> & {
|
|
352
|
+
readonly hooks: ErasedProgramHooksWithBeforeEach;
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* A command accepted by `runProgram()` with a program-level resource type.
|
|
356
|
+
*
|
|
357
|
+
* Commands without a command-level `beforeEach` must consume `R`. A command
|
|
358
|
+
* that always creates its own context may use a different resource type.
|
|
359
|
+
* Untyped calls retain the fully erased command shape for compatibility.
|
|
360
|
+
*
|
|
361
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
362
|
+
* @since 1.2.0
|
|
363
|
+
*/
|
|
364
|
+
type RunProgramCommand<R = unknown> = unknown extends R ? AnyCommand : ProgramResourceCommand<R> | OwnResourceCommand;
|
|
365
|
+
/**
|
|
366
|
+
* A static command accepted by `runProgram()` with a program-level resource
|
|
367
|
+
* type.
|
|
368
|
+
*
|
|
369
|
+
* Commands without a command-level `beforeEach` must consume `R`. A command
|
|
370
|
+
* that always creates its own context may use a different resource type.
|
|
371
|
+
* Untyped calls retain the fully erased command shape for compatibility.
|
|
372
|
+
*
|
|
373
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
374
|
+
* @since 1.2.0
|
|
375
|
+
*/
|
|
376
|
+
type RunProgramStaticCommand<R = unknown> = unknown extends R ? AnyStaticCommand : ProgramResourceStaticCommand<R> | OwnResourceStaticCommand;
|
|
246
377
|
/**
|
|
247
378
|
* Defines a command module for `@optique/discover`.
|
|
248
379
|
*
|
|
@@ -251,16 +382,33 @@ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
|
|
|
251
382
|
*
|
|
252
383
|
* @template M The mode of the command parser.
|
|
253
384
|
* @template T The parsed value passed to the command handler.
|
|
385
|
+
* @template R The resource made available to lifecycle hooks and the handler.
|
|
254
386
|
* @param command The command definition.
|
|
255
387
|
* @returns The same command definition with inferred types.
|
|
256
388
|
* @throws {TypeError} If the parser, path, handler, or hooks are missing or
|
|
257
389
|
* malformed.
|
|
258
390
|
* @since 1.1.0
|
|
259
391
|
*/
|
|
260
|
-
declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T> & {
|
|
392
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
|
|
393
|
+
readonly path: CommandPath;
|
|
394
|
+
} & {
|
|
395
|
+
readonly hooks: ProgramHooksWithBeforeEach<R>;
|
|
396
|
+
}): StaticCommandWithBeforeEach<M, T, R>;
|
|
397
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: Omit<CommandDefinition<M, T, R>, "hooks"> & {
|
|
398
|
+
readonly path: CommandPath;
|
|
399
|
+
} & {
|
|
400
|
+
readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
|
|
401
|
+
}): StaticCommandWithoutBeforeEach<M, T, R>;
|
|
402
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
|
|
403
|
+
readonly hooks: ProgramHooksWithBeforeEach<R>;
|
|
404
|
+
}): CommandWithBeforeEach<M, T, R>;
|
|
405
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: Omit<CommandDefinition<M, T, R>, "hooks"> & {
|
|
406
|
+
readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
|
|
407
|
+
}): CommandWithoutBeforeEach<M, T, R>;
|
|
408
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
|
|
261
409
|
readonly path: CommandPath;
|
|
262
|
-
}): StaticCommand<M, T>;
|
|
263
|
-
declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T>): Command<M, T>;
|
|
410
|
+
}): StaticCommand<M, T, R>;
|
|
411
|
+
declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R>): Command<M, T, R>;
|
|
264
412
|
/**
|
|
265
413
|
* Returns whether a value is a command created by {@link defineCommand}.
|
|
266
414
|
*
|
|
@@ -282,4 +430,4 @@ declare function isCommand(value: unknown): value is AnyCommand;
|
|
|
282
430
|
*/
|
|
283
431
|
declare function validateHooks(hooks: unknown, scope: "Command" | "Program"): asserts hooks is ProgramHooks;
|
|
284
432
|
//#endregion
|
|
285
|
-
export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks };
|
|
433
|
+
export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks };
|
package/dist/command.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-
|
|
2
|
-
export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks };
|
|
1
|
+
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-BtjFShKT.cjs";
|
|
2
|
+
export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks };
|
package/dist/command.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-
|
|
2
|
-
export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks };
|
|
1
|
+
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-BaFBKA4c.js";
|
|
2
|
+
export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_src = require('./src-
|
|
2
|
+
const require_src = require('./src-Bb2ONs5m.cjs');
|
|
3
3
|
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
4
4
|
const node_path = require_chunk.__toESM(require("node:path"));
|
|
5
5
|
const node_url = require_chunk.__toESM(require("node:url"));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDefaultExtensions } from "./src-
|
|
1
|
+
import { getDefaultExtensions } from "./src-Ddp18zFp.js";
|
|
2
2
|
import { mkdir, readdir, realpath, stat, writeFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, posix, relative, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
package/dist/generator.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require('./command-C-NgG0KJ.cjs');
|
|
2
|
-
require('./src-
|
|
3
|
-
const require_generator = require('./generator-
|
|
2
|
+
require('./src-Bb2ONs5m.cjs');
|
|
3
|
+
const require_generator = require('./generator-4mV9w1F0.cjs');
|
|
4
4
|
|
|
5
5
|
exports.generateCommandsModule = require_generator.generateCommandsModule;
|
|
6
6
|
exports.watchCommandsModule = require_generator.watchCommandsModule;
|
package/dist/generator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./command-9sgrJtwh.js";
|
|
2
|
-
import "./src-
|
|
3
|
-
import { generateCommandsModule, watchCommandsModule, writeCommandsModule } from "./generator-
|
|
2
|
+
import "./src-Ddp18zFp.js";
|
|
3
|
+
import { generateCommandsModule, watchCommandsModule, writeCommandsModule } from "./generator-CJiusCJb.js";
|
|
4
4
|
|
|
5
5
|
export { generateCommandsModule, watchCommandsModule, writeCommandsModule };
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_command = require('./command-C-NgG0KJ.cjs');
|
|
2
|
-
const require_src = require('./src-
|
|
2
|
+
const require_src = require('./src-Bb2ONs5m.cjs');
|
|
3
3
|
|
|
4
4
|
exports.commandsFromModules = require_src.commandsFromModules;
|
|
5
5
|
exports.createProgramParser = require_src.createProgramParser;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand } from "./command-
|
|
1
|
+
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand } from "./command-BtjFShKT.cjs";
|
|
2
2
|
import { Mode } from "@optique/core/parser";
|
|
3
3
|
import { FluentParser } from "@optique/core/fluent";
|
|
4
4
|
import { Message } from "@optique/core/message";
|
|
@@ -26,6 +26,20 @@ interface CommandEntry {
|
|
|
26
26
|
*/
|
|
27
27
|
readonly command: AnyCommand;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* A command entry accepted by `runProgram()` with a program-level resource
|
|
31
|
+
* type.
|
|
32
|
+
*
|
|
33
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
34
|
+
* @since 1.2.0
|
|
35
|
+
*/
|
|
36
|
+
type RunProgramCommandEntry<R = unknown> = Omit<CommandEntry, "command"> & {
|
|
37
|
+
/**
|
|
38
|
+
* A command compatible with the program-level resource, or one that
|
|
39
|
+
* always creates its own command context.
|
|
40
|
+
*/
|
|
41
|
+
readonly command: RunProgramCommand<R>;
|
|
42
|
+
};
|
|
29
43
|
/**
|
|
30
44
|
* A command found on disk.
|
|
31
45
|
*
|
|
@@ -48,9 +62,15 @@ interface DiscoveredCommand extends CommandEntry {
|
|
|
48
62
|
/**
|
|
49
63
|
* A command loaded from a static module map.
|
|
50
64
|
*
|
|
65
|
+
* @template R The program-level resource used by commands without their own
|
|
66
|
+
* `beforeEach` hook.
|
|
51
67
|
* @since 1.2.0
|
|
52
68
|
*/
|
|
53
|
-
interface ModuleCommand extends CommandEntry {
|
|
69
|
+
interface ModuleCommand<R = unknown> extends CommandEntry {
|
|
70
|
+
/**
|
|
71
|
+
* The command definition.
|
|
72
|
+
*/
|
|
73
|
+
readonly command: RunProgramCommand<R>;
|
|
54
74
|
/**
|
|
55
75
|
* Module map key used to derive the command path.
|
|
56
76
|
*/
|
|
@@ -146,7 +166,7 @@ interface RuntimeExtensionOptions {
|
|
|
146
166
|
*/
|
|
147
167
|
readonly nodeTypeScriptSupport?: boolean;
|
|
148
168
|
}
|
|
149
|
-
interface RunProgramBaseOptions extends Omit<RunOptions, "help" | "version" | "completion" | "programName"> {
|
|
169
|
+
interface RunProgramBaseOptions<R = unknown> extends Omit<RunOptions, "help" | "version" | "completion" | "programName"> {
|
|
150
170
|
/**
|
|
151
171
|
* Root program metadata.
|
|
152
172
|
*/
|
|
@@ -187,14 +207,15 @@ interface RunProgramBaseOptions extends Omit<RunOptions, "help" | "version" | "c
|
|
|
187
207
|
*
|
|
188
208
|
* @since 1.2.0
|
|
189
209
|
*/
|
|
190
|
-
readonly hooks?: ProgramHooks
|
|
210
|
+
readonly hooks?: ProgramHooks<R>;
|
|
191
211
|
}
|
|
192
212
|
/**
|
|
193
213
|
* Options for {@link runProgram} when discovering commands from files.
|
|
194
214
|
*
|
|
215
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
195
216
|
* @since 1.1.0
|
|
196
217
|
*/
|
|
197
|
-
interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
|
|
218
|
+
interface RunProgramDiscoveryOptions<R = unknown> extends RunProgramBaseOptions<R> {
|
|
198
219
|
/**
|
|
199
220
|
* Directory containing command modules.
|
|
200
221
|
*/
|
|
@@ -219,16 +240,17 @@ interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
|
|
|
219
240
|
/**
|
|
220
241
|
* Options for {@link runProgram} when commands are imported manually.
|
|
221
242
|
*
|
|
243
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
222
244
|
* @since 1.1.0
|
|
223
245
|
*/
|
|
224
|
-
interface RunProgramStaticOptions extends RunProgramBaseOptions {
|
|
246
|
+
interface RunProgramStaticOptions<R = unknown> extends RunProgramBaseOptions<R> {
|
|
225
247
|
/**
|
|
226
248
|
* Commands to compose without file-system discovery.
|
|
227
249
|
*
|
|
228
250
|
* Pass commands that declare their own `path`, or command entries returned
|
|
229
251
|
* by {@link commandsFromModules}.
|
|
230
252
|
*/
|
|
231
|
-
readonly commands: readonly (
|
|
253
|
+
readonly commands: readonly (RunProgramStaticCommand<NoInfer<R>> | RunProgramCommandEntry<NoInfer<R>>)[];
|
|
232
254
|
/**
|
|
233
255
|
* File-system discovery cannot be used together with `commands`.
|
|
234
256
|
*/
|
|
@@ -245,9 +267,10 @@ interface RunProgramStaticOptions extends RunProgramBaseOptions {
|
|
|
245
267
|
/**
|
|
246
268
|
* Options for {@link runProgram}.
|
|
247
269
|
*
|
|
270
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
248
271
|
* @since 1.1.0
|
|
249
272
|
*/
|
|
250
|
-
type RunProgramOptions = RunProgramDiscoveryOptions | RunProgramStaticOptions
|
|
273
|
+
type RunProgramOptions<R = unknown> = RunProgramDiscoveryOptions<R> | RunProgramStaticOptions<R>;
|
|
251
274
|
/**
|
|
252
275
|
* Returns runtime-aware command module suffixes.
|
|
253
276
|
*
|
|
@@ -274,6 +297,8 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
|
|
|
274
297
|
* see module maps, such as `import.meta.glob(..., { eager: true })`, while
|
|
275
298
|
* still deriving command paths from file-like module keys.
|
|
276
299
|
*
|
|
300
|
+
* @template R The program-level resource used by commands without their own
|
|
301
|
+
* `beforeEach` hook.
|
|
277
302
|
* @param modules Static module map keyed by module path.
|
|
278
303
|
* @param options Module path derivation options.
|
|
279
304
|
* @returns Command entries sorted by command path.
|
|
@@ -283,7 +308,7 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
|
|
|
283
308
|
* `path` does not match the module-derived path.
|
|
284
309
|
* @since 1.2.0
|
|
285
310
|
*/
|
|
286
|
-
declare function commandsFromModules(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand[];
|
|
311
|
+
declare function commandsFromModules<R = unknown>(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand<R>[];
|
|
287
312
|
/**
|
|
288
313
|
* Builds a parser that dispatches to discovered command handlers.
|
|
289
314
|
*
|
|
@@ -298,6 +323,7 @@ declare function createProgramParser(commands: readonly CommandEntry[], options?
|
|
|
298
323
|
/**
|
|
299
324
|
* Discovers and runs a command program.
|
|
300
325
|
*
|
|
326
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
301
327
|
* @param options Program options.
|
|
302
328
|
* @returns A promise that resolves after the selected command handler
|
|
303
329
|
* completes.
|
|
@@ -305,7 +331,7 @@ declare function createProgramParser(commands: readonly CommandEntry[], options?
|
|
|
305
331
|
* malformed.
|
|
306
332
|
* @since 1.1.0
|
|
307
333
|
*/
|
|
308
|
-
declare function runProgram(options: RunProgramOptions): Promise<void>;
|
|
334
|
+
declare function runProgram<R = unknown>(options: RunProgramOptions<R>): Promise<void>;
|
|
309
335
|
/**
|
|
310
336
|
* Root help metadata for {@link createProgramParser}.
|
|
311
337
|
*
|
|
@@ -339,4 +365,4 @@ interface CreateProgramParserOptions extends ProgramHelpMetadata {
|
|
|
339
365
|
readonly commandList?: RunOptions["commandList"];
|
|
340
366
|
}
|
|
341
367
|
//#endregion
|
|
342
|
-
export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, CreateProgramParserOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, type ProgramHookContext, type ProgramHooks, type ProgramInvocation, RunProgramDiscoveryOptions, RunProgramOptions, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
|
|
368
|
+
export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, CreateProgramParserOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, type ProgramHookContext, type ProgramHooks, type ProgramInvocation, type RunProgramCommand, RunProgramCommandEntry, RunProgramDiscoveryOptions, RunProgramOptions, type RunProgramStaticCommand, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand } from "./command-
|
|
1
|
+
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand } from "./command-BaFBKA4c.js";
|
|
2
2
|
import { Message } from "@optique/core/message";
|
|
3
3
|
import { ProgramMetadata } from "@optique/core/program";
|
|
4
4
|
import { RunOptions } from "@optique/run";
|
|
@@ -26,6 +26,20 @@ interface CommandEntry {
|
|
|
26
26
|
*/
|
|
27
27
|
readonly command: AnyCommand;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* A command entry accepted by `runProgram()` with a program-level resource
|
|
31
|
+
* type.
|
|
32
|
+
*
|
|
33
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
34
|
+
* @since 1.2.0
|
|
35
|
+
*/
|
|
36
|
+
type RunProgramCommandEntry<R = unknown> = Omit<CommandEntry, "command"> & {
|
|
37
|
+
/**
|
|
38
|
+
* A command compatible with the program-level resource, or one that
|
|
39
|
+
* always creates its own command context.
|
|
40
|
+
*/
|
|
41
|
+
readonly command: RunProgramCommand<R>;
|
|
42
|
+
};
|
|
29
43
|
/**
|
|
30
44
|
* A command found on disk.
|
|
31
45
|
*
|
|
@@ -48,9 +62,15 @@ interface DiscoveredCommand extends CommandEntry {
|
|
|
48
62
|
/**
|
|
49
63
|
* A command loaded from a static module map.
|
|
50
64
|
*
|
|
65
|
+
* @template R The program-level resource used by commands without their own
|
|
66
|
+
* `beforeEach` hook.
|
|
51
67
|
* @since 1.2.0
|
|
52
68
|
*/
|
|
53
|
-
interface ModuleCommand extends CommandEntry {
|
|
69
|
+
interface ModuleCommand<R = unknown> extends CommandEntry {
|
|
70
|
+
/**
|
|
71
|
+
* The command definition.
|
|
72
|
+
*/
|
|
73
|
+
readonly command: RunProgramCommand<R>;
|
|
54
74
|
/**
|
|
55
75
|
* Module map key used to derive the command path.
|
|
56
76
|
*/
|
|
@@ -146,7 +166,7 @@ interface RuntimeExtensionOptions {
|
|
|
146
166
|
*/
|
|
147
167
|
readonly nodeTypeScriptSupport?: boolean;
|
|
148
168
|
}
|
|
149
|
-
interface RunProgramBaseOptions extends Omit<RunOptions, "help" | "version" | "completion" | "programName"> {
|
|
169
|
+
interface RunProgramBaseOptions<R = unknown> extends Omit<RunOptions, "help" | "version" | "completion" | "programName"> {
|
|
150
170
|
/**
|
|
151
171
|
* Root program metadata.
|
|
152
172
|
*/
|
|
@@ -187,14 +207,15 @@ interface RunProgramBaseOptions extends Omit<RunOptions, "help" | "version" | "c
|
|
|
187
207
|
*
|
|
188
208
|
* @since 1.2.0
|
|
189
209
|
*/
|
|
190
|
-
readonly hooks?: ProgramHooks
|
|
210
|
+
readonly hooks?: ProgramHooks<R>;
|
|
191
211
|
}
|
|
192
212
|
/**
|
|
193
213
|
* Options for {@link runProgram} when discovering commands from files.
|
|
194
214
|
*
|
|
215
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
195
216
|
* @since 1.1.0
|
|
196
217
|
*/
|
|
197
|
-
interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
|
|
218
|
+
interface RunProgramDiscoveryOptions<R = unknown> extends RunProgramBaseOptions<R> {
|
|
198
219
|
/**
|
|
199
220
|
* Directory containing command modules.
|
|
200
221
|
*/
|
|
@@ -219,16 +240,17 @@ interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
|
|
|
219
240
|
/**
|
|
220
241
|
* Options for {@link runProgram} when commands are imported manually.
|
|
221
242
|
*
|
|
243
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
222
244
|
* @since 1.1.0
|
|
223
245
|
*/
|
|
224
|
-
interface RunProgramStaticOptions extends RunProgramBaseOptions {
|
|
246
|
+
interface RunProgramStaticOptions<R = unknown> extends RunProgramBaseOptions<R> {
|
|
225
247
|
/**
|
|
226
248
|
* Commands to compose without file-system discovery.
|
|
227
249
|
*
|
|
228
250
|
* Pass commands that declare their own `path`, or command entries returned
|
|
229
251
|
* by {@link commandsFromModules}.
|
|
230
252
|
*/
|
|
231
|
-
readonly commands: readonly (
|
|
253
|
+
readonly commands: readonly (RunProgramStaticCommand<NoInfer<R>> | RunProgramCommandEntry<NoInfer<R>>)[];
|
|
232
254
|
/**
|
|
233
255
|
* File-system discovery cannot be used together with `commands`.
|
|
234
256
|
*/
|
|
@@ -245,9 +267,10 @@ interface RunProgramStaticOptions extends RunProgramBaseOptions {
|
|
|
245
267
|
/**
|
|
246
268
|
* Options for {@link runProgram}.
|
|
247
269
|
*
|
|
270
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
248
271
|
* @since 1.1.0
|
|
249
272
|
*/
|
|
250
|
-
type RunProgramOptions = RunProgramDiscoveryOptions | RunProgramStaticOptions
|
|
273
|
+
type RunProgramOptions<R = unknown> = RunProgramDiscoveryOptions<R> | RunProgramStaticOptions<R>;
|
|
251
274
|
/**
|
|
252
275
|
* Returns runtime-aware command module suffixes.
|
|
253
276
|
*
|
|
@@ -274,6 +297,8 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
|
|
|
274
297
|
* see module maps, such as `import.meta.glob(..., { eager: true })`, while
|
|
275
298
|
* still deriving command paths from file-like module keys.
|
|
276
299
|
*
|
|
300
|
+
* @template R The program-level resource used by commands without their own
|
|
301
|
+
* `beforeEach` hook.
|
|
277
302
|
* @param modules Static module map keyed by module path.
|
|
278
303
|
* @param options Module path derivation options.
|
|
279
304
|
* @returns Command entries sorted by command path.
|
|
@@ -283,7 +308,7 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
|
|
|
283
308
|
* `path` does not match the module-derived path.
|
|
284
309
|
* @since 1.2.0
|
|
285
310
|
*/
|
|
286
|
-
declare function commandsFromModules(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand[];
|
|
311
|
+
declare function commandsFromModules<R = unknown>(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand<R>[];
|
|
287
312
|
/**
|
|
288
313
|
* Builds a parser that dispatches to discovered command handlers.
|
|
289
314
|
*
|
|
@@ -298,6 +323,7 @@ declare function createProgramParser(commands: readonly CommandEntry[], options?
|
|
|
298
323
|
/**
|
|
299
324
|
* Discovers and runs a command program.
|
|
300
325
|
*
|
|
326
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
301
327
|
* @param options Program options.
|
|
302
328
|
* @returns A promise that resolves after the selected command handler
|
|
303
329
|
* completes.
|
|
@@ -305,7 +331,7 @@ declare function createProgramParser(commands: readonly CommandEntry[], options?
|
|
|
305
331
|
* malformed.
|
|
306
332
|
* @since 1.1.0
|
|
307
333
|
*/
|
|
308
|
-
declare function runProgram(options: RunProgramOptions): Promise<void>;
|
|
334
|
+
declare function runProgram<R = unknown>(options: RunProgramOptions<R>): Promise<void>;
|
|
309
335
|
/**
|
|
310
336
|
* Root help metadata for {@link createProgramParser}.
|
|
311
337
|
*
|
|
@@ -339,4 +365,4 @@ interface CreateProgramParserOptions extends ProgramHelpMetadata {
|
|
|
339
365
|
readonly commandList?: RunOptions["commandList"];
|
|
340
366
|
}
|
|
341
367
|
//#endregion
|
|
342
|
-
export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, CreateProgramParserOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, type ProgramHookContext, type ProgramHooks, type ProgramInvocation, RunProgramDiscoveryOptions, RunProgramOptions, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
|
|
368
|
+
export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, CreateProgramParserOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, type ProgramHookContext, type ProgramHooks, type ProgramInvocation, type RunProgramCommand, RunProgramCommandEntry, RunProgramDiscoveryOptions, RunProgramOptions, type RunProgramStaticCommand, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { defineCommand, isCommand } from "./command-9sgrJtwh.js";
|
|
2
|
-
import { commandsFromModules, createProgramParser, discoverCommands, getDefaultExtensions, runProgram } from "./src-
|
|
2
|
+
import { commandsFromModules, createProgramParser, discoverCommands, getDefaultExtensions, runProgram } from "./src-Ddp18zFp.js";
|
|
3
3
|
|
|
4
4
|
export { commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
|
|
@@ -81,6 +81,8 @@ async function discoverCommands(options) {
|
|
|
81
81
|
* see module maps, such as `import.meta.glob(..., { eager: true })`, while
|
|
82
82
|
* still deriving command paths from file-like module keys.
|
|
83
83
|
*
|
|
84
|
+
* @template R The program-level resource used by commands without their own
|
|
85
|
+
* `beforeEach` hook.
|
|
84
86
|
* @param modules Static module map keyed by module path.
|
|
85
87
|
* @param options Module path derivation options.
|
|
86
88
|
* @returns Command entries sorted by command path.
|
|
@@ -144,6 +146,7 @@ function createProgramParser(commands, options = {}) {
|
|
|
144
146
|
/**
|
|
145
147
|
* Discovers and runs a command program.
|
|
146
148
|
*
|
|
149
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
147
150
|
* @param options Program options.
|
|
148
151
|
* @returns A promise that resolves after the selected command handler
|
|
149
152
|
* completes.
|
|
@@ -80,6 +80,8 @@ async function discoverCommands(options) {
|
|
|
80
80
|
* see module maps, such as `import.meta.glob(..., { eager: true })`, while
|
|
81
81
|
* still deriving command paths from file-like module keys.
|
|
82
82
|
*
|
|
83
|
+
* @template R The program-level resource used by commands without their own
|
|
84
|
+
* `beforeEach` hook.
|
|
83
85
|
* @param modules Static module map keyed by module path.
|
|
84
86
|
* @param options Module path derivation options.
|
|
85
87
|
* @returns Command entries sorted by command path.
|
|
@@ -143,6 +145,7 @@ function createProgramParser(commands, options = {}) {
|
|
|
143
145
|
/**
|
|
144
146
|
* Discovers and runs a command program.
|
|
145
147
|
*
|
|
148
|
+
* @template R The resource made available by program-level lifecycle hooks.
|
|
146
149
|
* @param options Program options.
|
|
147
150
|
* @returns A promise that resolves after the selected command handler
|
|
148
151
|
* completes.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/discover",
|
|
3
|
-
"version": "1.2.0-dev.
|
|
3
|
+
"version": "1.2.0-dev.2333",
|
|
4
4
|
"description": "Runtime-aware command discovery for Optique CLI programs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"optique-discover": "./dist/cli.js"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@optique/core": "1.2.0-dev.
|
|
87
|
-
"@optique/run": "1.2.0-dev.
|
|
86
|
+
"@optique/core": "1.2.0-dev.2333+f7f47e8b",
|
|
87
|
+
"@optique/run": "1.2.0-dev.2333+f7f47e8b"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@types/node": "^24.0.0",
|