1- import { commands , field , object , program , help } from "configliere" ;
1+ import {
2+ commands ,
3+ field ,
4+ object ,
5+ program ,
6+ help ,
7+ type CommandsParser ,
8+ type ObjectParser ,
9+ } from "configliere" ;
210import packageJSON from "../package.json" with { type : "json" } ;
311import { type } from "arktype" ;
412import { scope , player } from "../lib/protocols.ts" ;
513import { combine } from "../mod.ts" ;
614
715export const inspector = combine . protocols ( scope . protocol , player . protocol ) ;
16+
17+ const commandBase = object ( {
18+ out : {
19+ description : "write out the response to a file" ,
20+ ...field ( type ( "string | undefined" ) , field . default ( undefined ) ) ,
21+ } ,
22+ host : {
23+ description : "inspector base URL (overrides default)" ,
24+ ...field ( type ( "string" ) , field . default ( "http://localhost:41000" ) ) ,
25+ } ,
26+ } ) ;
27+ type InspectorProtocolCommandBase = Record <
28+ keyof typeof inspector . methods ,
29+ { description : string } & typeof commandBase
30+ > ;
831const inspectorProtocolEntries = (
932 Object . keys ( inspector . methods ) as ( keyof typeof inspector . methods ) [ ]
10- ) . reduce (
11- ( base , current ) => {
12- base [ current ] = {
13- description : `/${ current } API` ,
14- ...object ( {
15- out : {
16- description : "write out the response to a file" ,
17- ...field ( type ( "string | undefined" ) , field . default ( undefined ) ) ,
18- } ,
19- host : {
20- description : "inspector base URL (overrides default)" ,
21- ...field ( type ( "string" ) , field . default ( "http://localhost:41000" ) ) ,
22- } ,
23- } ) ,
24- } ;
25- return base ;
26- } ,
27- { } as Record < keyof typeof inspector . methods , { } > ,
28- ) ;
33+ ) . reduce ( ( base , current ) => {
34+ base [ current ] = {
35+ description : `/${ current } API` ,
36+ ...commandBase ,
37+ } ;
38+ return base satisfies InspectorProtocolCommandBase ;
39+ } , { } as InspectorProtocolCommandBase ) ;
2940
3041const protocolCommands = commands ( inspectorProtocolEntries ) ;
31- export type ProtocolCommands = typeof protocolCommands ;
42+ export type ParsedConfig < T extends CommandsParser | ObjectParser < any > > = Extract <
43+ ReturnType < T [ "parse" ] > ,
44+ { ok : true }
45+ > [ "value" ] ;
46+ export type ProtocolCommandConfig = ParsedConfig < typeof protocolCommands > ;
47+
48+ const runBase = object ( {
49+ inspectPause : {
50+ description : "start program paused until resumed by inspector" ,
51+ ...field ( type ( "boolean" ) , field . default ( false ) ) ,
52+ } ,
53+ inspectRecord : {
54+ description : "write inspector recording to the given file" ,
55+ ...field ( type ( "string | undefined" ) , field . default ( undefined ) ) ,
56+ } ,
57+ inspectHost : {
58+ description : "inspector base URL (overrides default)" ,
59+ ...field ( type ( "string.url" ) , field . default ( "http://localhost:41000" ) ) ,
60+ } ,
61+ inspectRuntime : {
62+ description :
63+ "which JavaScript runtime to launch (node, deno, bun).\n" +
64+ "If omitted we infer from the executable that invoked the CLI" ,
65+ ...field ( type ( "string" ) , field . default ( "node" ) ) ,
66+ } ,
67+ } ) ;
3268
3369export const config = program ( {
3470 name : "inspector" ,
@@ -46,28 +82,11 @@ export const config = program({
4682 } ,
4783 run : {
4884 description : "inspect a CLI program" ,
49- ...object ( {
50- inspectPause : {
51- description : "start program paused until resumed by inspector" ,
52- ...field ( type ( "boolean" ) , field . default ( false ) ) ,
53- } ,
54- inspectRecord : {
55- description : "write inspector recording to the given file" ,
56- ...field ( type ( "string | undefined" ) , field . default ( undefined ) ) ,
57- } ,
58- inspectHost : {
59- description : "inspector base URL (overrides default)" ,
60- ...field ( type ( "string.url" ) , field . default ( "http://localhost:41000" ) ) ,
61- } ,
62- inspectRuntime : {
63- description :
64- "which JavaScript runtime to launch (node, deno, bun).\n" +
65- "If omitted we infer from the executable that invoked the CLI" ,
66- ...field ( type ( "string" ) , field . default ( "node" ) ) ,
67- } ,
68- } ) ,
85+ ...runBase ,
6986 } ,
7087 } ,
7188 { default : "run" } ,
7289 ) ,
7390} ) ;
91+
92+ export type RunConfig = ParsedConfig < typeof runBase > ;
0 commit comments