@optique/discover 1.2.0-dev.2330 → 1.2.0-dev.2331

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 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-CPtrcNkd.cjs');
5
- const require_generator = require('./generator-Dc9I4tTs.cjs');
4
+ require('./src-BAFFLASv.cjs');
5
+ const require_generator = require('./generator-DX58yLaB.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.2330+6776ce17";
18
+ var version = "1.2.0-dev.2331+0f3b5a2e";
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-CCeOMJRj.js";
4
- import { watchCommandsModule, writeCommandsModule } from "./generator-wZHULCZH.js";
3
+ import "./src-Bxt-nAIP.js";
4
+ import { watchCommandsModule, writeCommandsModule } from "./generator-wG1l1zon.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.2330+6776ce17";
17
+ var version = "1.2.0-dev.2331+0f3b5a2e";
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?: unknown;
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, result: unknown) => void | Promise<void>;
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,17 @@ interface ProgramHooks {
135
137
  *
136
138
  * Returning a promise is supported; the dispatcher awaits it.
137
139
  */
138
- readonly onError?: (context: ProgramHookContext, error: unknown) => void | Promise<void>;
140
+ readonly onError?: (context: ProgramHookContext<R>, error: unknown) => void | Promise<void>;
139
141
  }
140
142
  /**
141
143
  * Input accepted by {@link defineCommand}.
142
144
  *
143
145
  * @template M The mode of the command parser.
144
146
  * @template T The parsed value passed to the command handler.
147
+ * @template R The resource made available to lifecycle hooks and the handler.
145
148
  * @since 1.1.0
146
149
  */
147
- interface CommandDefinition<M extends Mode, T> {
150
+ interface CommandDefinition<M extends Mode, T, R = unknown> {
148
151
  /**
149
152
  * Command path used when commands are passed directly to `runProgram()`.
150
153
  * Use an empty path (`[]`) to register the root command.
@@ -172,7 +175,7 @@ interface CommandDefinition<M extends Mode, T> {
172
175
  *
173
176
  * @since 1.2.0
174
177
  */
175
- readonly hooks?: ProgramHooks;
178
+ readonly hooks?: ProgramHooks<R>;
176
179
  /**
177
180
  * Handles the parsed command value.
178
181
  *
@@ -185,16 +188,17 @@ interface CommandDefinition<M extends Mode, T> {
185
188
  * @returns Nothing, or a promise that resolves when command handling
186
189
  * completes.
187
190
  */
188
- readonly handler: (value: T, context?: ProgramHookContext) => void | Promise<void>;
191
+ readonly handler: (value: T, context?: ProgramHookContext<R>) => void | Promise<void>;
189
192
  }
190
193
  /**
191
194
  * A discovered command module definition.
192
195
  *
193
196
  * @template M The mode of the command parser.
194
197
  * @template T The parsed value passed to the command handler.
198
+ * @template R The resource made available to lifecycle hooks and the handler.
195
199
  * @since 1.1.0
196
200
  */
197
- interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
201
+ interface Command<M extends Mode, T, R = unknown> extends CommandDefinition<M, T, R> {
198
202
  /**
199
203
  * Internal marker used to validate discovered modules.
200
204
  *
@@ -209,14 +213,25 @@ interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
209
213
  *
210
214
  * @template M The mode of the command parser.
211
215
  * @template T The parsed value passed to the command handler.
216
+ * @template R The resource made available to lifecycle hooks and the handler.
212
217
  * @since 1.1.0
213
218
  */
214
- interface StaticCommand<M extends Mode, T> extends Command<M, T> {
219
+ interface StaticCommand<M extends Mode, T, R = unknown> extends Command<M, T, R> {
215
220
  /**
216
221
  * Command path used by static command registration.
217
222
  */
218
223
  readonly path: CommandPath;
219
224
  }
225
+ /**
226
+ * Lifecycle hooks whose caller-defined resource type has been erased.
227
+ *
228
+ * @internal
229
+ */
230
+ interface ErasedProgramHooks {
231
+ readonly beforeEach?: ProgramHooks<unknown>["beforeEach"];
232
+ readonly afterEach?: ProgramHooks<never>["afterEach"];
233
+ readonly onError?: ProgramHooks<never>["onError"];
234
+ }
220
235
  /**
221
236
  * A command with its handler value type erased.
222
237
  *
@@ -226,22 +241,30 @@ interface StaticCommand<M extends Mode, T> extends Command<M, T> {
226
241
  *
227
242
  * @since 1.1.0
228
243
  */
229
- type AnyCommand = Omit<Command<Mode, unknown>, "handler"> & {
244
+ type AnyCommand = Omit<Command<Mode, unknown>, "handler" | "hooks"> & {
245
+ /**
246
+ * Lifecycle hooks with their caller-defined resource type erased.
247
+ */
248
+ readonly hooks?: ErasedProgramHooks;
230
249
  /**
231
250
  * Erased command handler.
232
251
  */
233
- readonly handler: (value: never, context?: ProgramHookContext) => void | Promise<void>;
252
+ readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
234
253
  };
235
254
  /**
236
255
  * A statically registered command with its handler value type erased.
237
256
  *
238
257
  * @since 1.1.0
239
258
  */
240
- type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
259
+ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler" | "hooks"> & {
260
+ /**
261
+ * Lifecycle hooks with their caller-defined resource type erased.
262
+ */
263
+ readonly hooks?: ErasedProgramHooks;
241
264
  /**
242
265
  * Erased command handler.
243
266
  */
244
- readonly handler: (value: never, context?: ProgramHookContext) => void | Promise<void>;
267
+ readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
245
268
  };
246
269
  /**
247
270
  * Defines a command module for `@optique/discover`.
@@ -251,16 +274,17 @@ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
251
274
  *
252
275
  * @template M The mode of the command parser.
253
276
  * @template T The parsed value passed to the command handler.
277
+ * @template R The resource made available to lifecycle hooks and the handler.
254
278
  * @param command The command definition.
255
279
  * @returns The same command definition with inferred types.
256
280
  * @throws {TypeError} If the parser, path, handler, or hooks are missing or
257
281
  * malformed.
258
282
  * @since 1.1.0
259
283
  */
260
- declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T> & {
284
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
261
285
  readonly path: CommandPath;
262
- }): StaticCommand<M, T>;
263
- declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T>): Command<M, T>;
286
+ }): StaticCommand<M, T, R>;
287
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R>): Command<M, T, R>;
264
288
  /**
265
289
  * Returns whether a value is a command created by {@link defineCommand}.
266
290
  *
@@ -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?: unknown;
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, result: unknown) => void | Promise<void>;
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,17 @@ interface ProgramHooks {
135
137
  *
136
138
  * Returning a promise is supported; the dispatcher awaits it.
137
139
  */
138
- readonly onError?: (context: ProgramHookContext, error: unknown) => void | Promise<void>;
140
+ readonly onError?: (context: ProgramHookContext<R>, error: unknown) => void | Promise<void>;
139
141
  }
140
142
  /**
141
143
  * Input accepted by {@link defineCommand}.
142
144
  *
143
145
  * @template M The mode of the command parser.
144
146
  * @template T The parsed value passed to the command handler.
147
+ * @template R The resource made available to lifecycle hooks and the handler.
145
148
  * @since 1.1.0
146
149
  */
147
- interface CommandDefinition<M extends Mode, T> {
150
+ interface CommandDefinition<M extends Mode, T, R = unknown> {
148
151
  /**
149
152
  * Command path used when commands are passed directly to `runProgram()`.
150
153
  * Use an empty path (`[]`) to register the root command.
@@ -172,7 +175,7 @@ interface CommandDefinition<M extends Mode, T> {
172
175
  *
173
176
  * @since 1.2.0
174
177
  */
175
- readonly hooks?: ProgramHooks;
178
+ readonly hooks?: ProgramHooks<R>;
176
179
  /**
177
180
  * Handles the parsed command value.
178
181
  *
@@ -185,16 +188,17 @@ interface CommandDefinition<M extends Mode, T> {
185
188
  * @returns Nothing, or a promise that resolves when command handling
186
189
  * completes.
187
190
  */
188
- readonly handler: (value: T, context?: ProgramHookContext) => void | Promise<void>;
191
+ readonly handler: (value: T, context?: ProgramHookContext<R>) => void | Promise<void>;
189
192
  }
190
193
  /**
191
194
  * A discovered command module definition.
192
195
  *
193
196
  * @template M The mode of the command parser.
194
197
  * @template T The parsed value passed to the command handler.
198
+ * @template R The resource made available to lifecycle hooks and the handler.
195
199
  * @since 1.1.0
196
200
  */
197
- interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
201
+ interface Command<M extends Mode, T, R = unknown> extends CommandDefinition<M, T, R> {
198
202
  /**
199
203
  * Internal marker used to validate discovered modules.
200
204
  *
@@ -209,14 +213,25 @@ interface Command<M extends Mode, T> extends CommandDefinition<M, T> {
209
213
  *
210
214
  * @template M The mode of the command parser.
211
215
  * @template T The parsed value passed to the command handler.
216
+ * @template R The resource made available to lifecycle hooks and the handler.
212
217
  * @since 1.1.0
213
218
  */
214
- interface StaticCommand<M extends Mode, T> extends Command<M, T> {
219
+ interface StaticCommand<M extends Mode, T, R = unknown> extends Command<M, T, R> {
215
220
  /**
216
221
  * Command path used by static command registration.
217
222
  */
218
223
  readonly path: CommandPath;
219
224
  }
225
+ /**
226
+ * Lifecycle hooks whose caller-defined resource type has been erased.
227
+ *
228
+ * @internal
229
+ */
230
+ interface ErasedProgramHooks {
231
+ readonly beforeEach?: ProgramHooks<unknown>["beforeEach"];
232
+ readonly afterEach?: ProgramHooks<never>["afterEach"];
233
+ readonly onError?: ProgramHooks<never>["onError"];
234
+ }
220
235
  /**
221
236
  * A command with its handler value type erased.
222
237
  *
@@ -226,22 +241,30 @@ interface StaticCommand<M extends Mode, T> extends Command<M, T> {
226
241
  *
227
242
  * @since 1.1.0
228
243
  */
229
- type AnyCommand = Omit<Command<Mode, unknown>, "handler"> & {
244
+ type AnyCommand = Omit<Command<Mode, unknown>, "handler" | "hooks"> & {
245
+ /**
246
+ * Lifecycle hooks with their caller-defined resource type erased.
247
+ */
248
+ readonly hooks?: ErasedProgramHooks;
230
249
  /**
231
250
  * Erased command handler.
232
251
  */
233
- readonly handler: (value: never, context?: ProgramHookContext) => void | Promise<void>;
252
+ readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
234
253
  };
235
254
  /**
236
255
  * A statically registered command with its handler value type erased.
237
256
  *
238
257
  * @since 1.1.0
239
258
  */
240
- type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
259
+ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler" | "hooks"> & {
260
+ /**
261
+ * Lifecycle hooks with their caller-defined resource type erased.
262
+ */
263
+ readonly hooks?: ErasedProgramHooks;
241
264
  /**
242
265
  * Erased command handler.
243
266
  */
244
- readonly handler: (value: never, context?: ProgramHookContext) => void | Promise<void>;
267
+ readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
245
268
  };
246
269
  /**
247
270
  * Defines a command module for `@optique/discover`.
@@ -251,16 +274,17 @@ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler"> & {
251
274
  *
252
275
  * @template M The mode of the command parser.
253
276
  * @template T The parsed value passed to the command handler.
277
+ * @template R The resource made available to lifecycle hooks and the handler.
254
278
  * @param command The command definition.
255
279
  * @returns The same command definition with inferred types.
256
280
  * @throws {TypeError} If the parser, path, handler, or hooks are missing or
257
281
  * malformed.
258
282
  * @since 1.1.0
259
283
  */
260
- declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T> & {
284
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
261
285
  readonly path: CommandPath;
262
- }): StaticCommand<M, T>;
263
- declare function defineCommand<M extends Mode, T>(command: CommandDefinition<M, T>): Command<M, T>;
286
+ }): StaticCommand<M, T, R>;
287
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R>): Command<M, T, R>;
264
288
  /**
265
289
  * Returns whether a value is a command created by {@link defineCommand}.
266
290
  *
@@ -1,2 +1,2 @@
1
- import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-Dvg452tU.cjs";
1
+ import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-ChWCwb3x.cjs";
2
2
  export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, 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-egqHCvDL.js";
1
+ import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-CYwk-AJC.js";
2
2
  export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks };
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_src = require('./src-CPtrcNkd.cjs');
2
+ const require_src = require('./src-BAFFLASv.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-CCeOMJRj.js";
1
+ import { getDefaultExtensions } from "./src-Bxt-nAIP.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";
@@ -1,6 +1,6 @@
1
1
  require('./command-C-NgG0KJ.cjs');
2
- require('./src-CPtrcNkd.cjs');
3
- const require_generator = require('./generator-Dc9I4tTs.cjs');
2
+ require('./src-BAFFLASv.cjs');
3
+ const require_generator = require('./generator-DX58yLaB.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-CCeOMJRj.js";
3
- import { generateCommandsModule, watchCommandsModule, writeCommandsModule } from "./generator-wZHULCZH.js";
2
+ import "./src-Bxt-nAIP.js";
3
+ import { generateCommandsModule, watchCommandsModule, writeCommandsModule } from "./generator-wG1l1zon.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-CPtrcNkd.cjs');
2
+ const require_src = require('./src-BAFFLASv.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-Dvg452tU.cjs";
1
+ import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand } from "./command-ChWCwb3x.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";
@@ -146,7 +146,7 @@ interface RuntimeExtensionOptions {
146
146
  */
147
147
  readonly nodeTypeScriptSupport?: boolean;
148
148
  }
149
- interface RunProgramBaseOptions extends Omit<RunOptions, "help" | "version" | "completion" | "programName"> {
149
+ interface RunProgramBaseOptions<R = unknown> extends Omit<RunOptions, "help" | "version" | "completion" | "programName"> {
150
150
  /**
151
151
  * Root program metadata.
152
152
  */
@@ -187,14 +187,15 @@ interface RunProgramBaseOptions extends Omit<RunOptions, "help" | "version" | "c
187
187
  *
188
188
  * @since 1.2.0
189
189
  */
190
- readonly hooks?: ProgramHooks;
190
+ readonly hooks?: ProgramHooks<R>;
191
191
  }
192
192
  /**
193
193
  * Options for {@link runProgram} when discovering commands from files.
194
194
  *
195
+ * @template R The resource made available by program-level lifecycle hooks.
195
196
  * @since 1.1.0
196
197
  */
197
- interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
198
+ interface RunProgramDiscoveryOptions<R = unknown> extends RunProgramBaseOptions<R> {
198
199
  /**
199
200
  * Directory containing command modules.
200
201
  */
@@ -219,9 +220,10 @@ interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
219
220
  /**
220
221
  * Options for {@link runProgram} when commands are imported manually.
221
222
  *
223
+ * @template R The resource made available by program-level lifecycle hooks.
222
224
  * @since 1.1.0
223
225
  */
224
- interface RunProgramStaticOptions extends RunProgramBaseOptions {
226
+ interface RunProgramStaticOptions<R = unknown> extends RunProgramBaseOptions<R> {
225
227
  /**
226
228
  * Commands to compose without file-system discovery.
227
229
  *
@@ -245,9 +247,10 @@ interface RunProgramStaticOptions extends RunProgramBaseOptions {
245
247
  /**
246
248
  * Options for {@link runProgram}.
247
249
  *
250
+ * @template R The resource made available by program-level lifecycle hooks.
248
251
  * @since 1.1.0
249
252
  */
250
- type RunProgramOptions = RunProgramDiscoveryOptions | RunProgramStaticOptions;
253
+ type RunProgramOptions<R = unknown> = RunProgramDiscoveryOptions<R> | RunProgramStaticOptions<R>;
251
254
  /**
252
255
  * Returns runtime-aware command module suffixes.
253
256
  *
@@ -298,6 +301,7 @@ declare function createProgramParser(commands: readonly CommandEntry[], options?
298
301
  /**
299
302
  * Discovers and runs a command program.
300
303
  *
304
+ * @template R The resource made available by program-level lifecycle hooks.
301
305
  * @param options Program options.
302
306
  * @returns A promise that resolves after the selected command handler
303
307
  * completes.
@@ -305,7 +309,7 @@ declare function createProgramParser(commands: readonly CommandEntry[], options?
305
309
  * malformed.
306
310
  * @since 1.1.0
307
311
  */
308
- declare function runProgram(options: RunProgramOptions): Promise<void>;
312
+ declare function runProgram<R = unknown>(options: RunProgramOptions<R>): Promise<void>;
309
313
  /**
310
314
  * Root help metadata for {@link createProgramParser}.
311
315
  *
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-egqHCvDL.js";
1
+ import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand } from "./command-CYwk-AJC.js";
2
2
  import { Message } from "@optique/core/message";
3
3
  import { ProgramMetadata } from "@optique/core/program";
4
4
  import { RunOptions } from "@optique/run";
@@ -146,7 +146,7 @@ interface RuntimeExtensionOptions {
146
146
  */
147
147
  readonly nodeTypeScriptSupport?: boolean;
148
148
  }
149
- interface RunProgramBaseOptions extends Omit<RunOptions, "help" | "version" | "completion" | "programName"> {
149
+ interface RunProgramBaseOptions<R = unknown> extends Omit<RunOptions, "help" | "version" | "completion" | "programName"> {
150
150
  /**
151
151
  * Root program metadata.
152
152
  */
@@ -187,14 +187,15 @@ interface RunProgramBaseOptions extends Omit<RunOptions, "help" | "version" | "c
187
187
  *
188
188
  * @since 1.2.0
189
189
  */
190
- readonly hooks?: ProgramHooks;
190
+ readonly hooks?: ProgramHooks<R>;
191
191
  }
192
192
  /**
193
193
  * Options for {@link runProgram} when discovering commands from files.
194
194
  *
195
+ * @template R The resource made available by program-level lifecycle hooks.
195
196
  * @since 1.1.0
196
197
  */
197
- interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
198
+ interface RunProgramDiscoveryOptions<R = unknown> extends RunProgramBaseOptions<R> {
198
199
  /**
199
200
  * Directory containing command modules.
200
201
  */
@@ -219,9 +220,10 @@ interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
219
220
  /**
220
221
  * Options for {@link runProgram} when commands are imported manually.
221
222
  *
223
+ * @template R The resource made available by program-level lifecycle hooks.
222
224
  * @since 1.1.0
223
225
  */
224
- interface RunProgramStaticOptions extends RunProgramBaseOptions {
226
+ interface RunProgramStaticOptions<R = unknown> extends RunProgramBaseOptions<R> {
225
227
  /**
226
228
  * Commands to compose without file-system discovery.
227
229
  *
@@ -245,9 +247,10 @@ interface RunProgramStaticOptions extends RunProgramBaseOptions {
245
247
  /**
246
248
  * Options for {@link runProgram}.
247
249
  *
250
+ * @template R The resource made available by program-level lifecycle hooks.
248
251
  * @since 1.1.0
249
252
  */
250
- type RunProgramOptions = RunProgramDiscoveryOptions | RunProgramStaticOptions;
253
+ type RunProgramOptions<R = unknown> = RunProgramDiscoveryOptions<R> | RunProgramStaticOptions<R>;
251
254
  /**
252
255
  * Returns runtime-aware command module suffixes.
253
256
  *
@@ -298,6 +301,7 @@ declare function createProgramParser(commands: readonly CommandEntry[], options?
298
301
  /**
299
302
  * Discovers and runs a command program.
300
303
  *
304
+ * @template R The resource made available by program-level lifecycle hooks.
301
305
  * @param options Program options.
302
306
  * @returns A promise that resolves after the selected command handler
303
307
  * completes.
@@ -305,7 +309,7 @@ declare function createProgramParser(commands: readonly CommandEntry[], options?
305
309
  * malformed.
306
310
  * @since 1.1.0
307
311
  */
308
- declare function runProgram(options: RunProgramOptions): Promise<void>;
312
+ declare function runProgram<R = unknown>(options: RunProgramOptions<R>): Promise<void>;
309
313
  /**
310
314
  * Root help metadata for {@link createProgramParser}.
311
315
  *
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-CCeOMJRj.js";
2
+ import { commandsFromModules, createProgramParser, discoverCommands, getDefaultExtensions, runProgram } from "./src-Bxt-nAIP.js";
3
3
 
4
4
  export { commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
@@ -144,6 +144,7 @@ function createProgramParser(commands, options = {}) {
144
144
  /**
145
145
  * Discovers and runs a command program.
146
146
  *
147
+ * @template R The resource made available by program-level lifecycle hooks.
147
148
  * @param options Program options.
148
149
  * @returns A promise that resolves after the selected command handler
149
150
  * completes.
@@ -143,6 +143,7 @@ function createProgramParser(commands, options = {}) {
143
143
  /**
144
144
  * Discovers and runs a command program.
145
145
  *
146
+ * @template R The resource made available by program-level lifecycle hooks.
146
147
  * @param options Program options.
147
148
  * @returns A promise that resolves after the selected command handler
148
149
  * completes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/discover",
3
- "version": "1.2.0-dev.2330",
3
+ "version": "1.2.0-dev.2331",
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.2330+6776ce17",
87
- "@optique/run": "1.2.0-dev.2330+6776ce17"
86
+ "@optique/core": "1.2.0-dev.2331+0f3b5a2e",
87
+ "@optique/run": "1.2.0-dev.2331+0f3b5a2e"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@types/node": "^24.0.0",