@kjanat/dreamcli 2.0.0 → 2.1.0

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.
@@ -9,7 +9,13 @@
9
9
  * @module dreamcli/core/schema/flag
10
10
  */
11
11
 
12
- import type { PromptConfig } from './prompt.ts';
12
+ import type {
13
+ ConfirmPromptConfig,
14
+ InputPromptConfig,
15
+ MultiselectPromptConfig,
16
+ PromptConfig,
17
+ SelectPromptConfig,
18
+ } from './prompt.ts';
13
19
 
14
20
  // --- Type-level configuration (phantom state tracked through the chain)
15
21
 
@@ -48,6 +54,8 @@ interface FlagConfig {
48
54
  readonly presence: FlagPresence;
49
55
  /** What an unresolved optional flag becomes at the action boundary. */
50
56
  readonly optionalFallback: OptionalFallback;
57
+ /** The runtime kind discriminator, mirroring {@link FlagKind}. */
58
+ readonly flagKind: FlagKind;
51
59
  }
52
60
 
53
61
  // --- Type-level helpers
@@ -60,6 +68,7 @@ type WithPresence<C extends FlagConfig, P extends FlagPresence> = {
60
68
  readonly valueType: C['valueType'];
61
69
  readonly presence: P;
62
70
  readonly optionalFallback: C['optionalFallback'];
71
+ readonly flagKind: C['flagKind'];
63
72
  };
64
73
 
65
74
  /**
@@ -87,6 +96,29 @@ type InferFlags<T extends Record<string, FlagBuilder<FlagConfig>>> = {
87
96
  [K in keyof T]: InferFlag<T[K]>;
88
97
  };
89
98
 
99
+ /**
100
+ * Maps a {@linkcode FlagConfig} to the prompt config types that are compatible
101
+ * with the flag's kind. Prevents compile-time mismatches such as
102
+ * `flag.enum([…]).prompt({ kind: 'multiselect' })`.
103
+ *
104
+ * - `'boolean'` → {@link ConfirmPromptConfig}
105
+ * - `'string'` → {@link InputPromptConfig} | {@link SelectPromptConfig}
106
+ * - `'number'` → {@link InputPromptConfig}
107
+ * - `'enum'` → {@link SelectPromptConfig} | {@link InputPromptConfig}
108
+ * - `'array'` → {@link MultiselectPromptConfig}
109
+ * - `'custom'` → all prompt kinds ({@link PromptConfig})
110
+ */
111
+ type PromptConfigByFlagKind = {
112
+ readonly string: InputPromptConfig | SelectPromptConfig;
113
+ readonly number: InputPromptConfig;
114
+ readonly boolean: ConfirmPromptConfig;
115
+ readonly enum: SelectPromptConfig | InputPromptConfig;
116
+ readonly array: MultiselectPromptConfig;
117
+ readonly custom: PromptConfig;
118
+ };
119
+
120
+ type AllowedPromptConfig<C extends FlagConfig> = PromptConfigByFlagKind[C['flagKind']];
121
+
90
122
  // --- Runtime schema data
91
123
 
92
124
  /** All flag kind discriminators as a runtime array. */
@@ -469,7 +501,7 @@ class FlagBuilder<C extends FlagConfig> {
469
501
  * // $ mycli init --name foo → skips prompt, uses CLI value
470
502
  * ```
471
503
  */
472
- prompt(config: PromptConfig): FlagBuilder<C> {
504
+ prompt(config: AllowedPromptConfig<C>): FlagBuilder<C> {
473
505
  return new FlagBuilder({
474
506
  ...this.schema,
475
507
  prompt: config,
@@ -547,6 +579,7 @@ interface FlagFactory {
547
579
  readonly valueType: string;
548
580
  readonly presence: 'optional';
549
581
  readonly optionalFallback: 'undefined';
582
+ readonly flagKind: 'string';
550
583
  }>;
551
584
 
552
585
  /**
@@ -558,6 +591,7 @@ interface FlagFactory {
558
591
  readonly valueType: number;
559
592
  readonly presence: 'optional';
560
593
  readonly optionalFallback: 'undefined';
594
+ readonly flagKind: 'number';
561
595
  }>;
562
596
 
563
597
  /**
@@ -570,6 +604,7 @@ interface FlagFactory {
570
604
  readonly valueType: boolean;
571
605
  readonly presence: 'defaulted';
572
606
  readonly optionalFallback: 'undefined';
607
+ readonly flagKind: 'boolean';
573
608
  }>;
574
609
 
575
610
  /**
@@ -593,6 +628,7 @@ interface FlagFactory {
593
628
  readonly valueType: T[number];
594
629
  readonly presence: 'optional';
595
630
  readonly optionalFallback: 'undefined';
631
+ readonly flagKind: 'enum';
596
632
  }>;
597
633
 
598
634
  /**
@@ -613,6 +649,7 @@ interface FlagFactory {
613
649
  readonly valueType: E['valueType'][];
614
650
  readonly presence: 'optional';
615
651
  readonly optionalFallback: 'empty-array';
652
+ readonly flagKind: 'array';
616
653
  }>;
617
654
 
618
655
  /**
@@ -648,6 +685,7 @@ interface FlagFactory {
648
685
  readonly valueType: T;
649
686
  readonly presence: 'optional';
650
687
  readonly optionalFallback: 'undefined';
688
+ readonly flagKind: 'custom';
651
689
  }>;
652
690
  }
653
691
 
@@ -660,6 +698,7 @@ const flag: FlagFactory = {
660
698
  readonly valueType: string;
661
699
  readonly presence: 'optional';
662
700
  readonly optionalFallback: 'undefined';
701
+ readonly flagKind: 'string';
663
702
  }> {
664
703
  return new FlagBuilder(createSchema('string'));
665
704
  },
@@ -668,6 +707,7 @@ const flag: FlagFactory = {
668
707
  readonly valueType: number;
669
708
  readonly presence: 'optional';
670
709
  readonly optionalFallback: 'undefined';
710
+ readonly flagKind: 'number';
671
711
  }> {
672
712
  return new FlagBuilder(createSchema('number'));
673
713
  },
@@ -676,6 +716,7 @@ const flag: FlagFactory = {
676
716
  readonly valueType: boolean;
677
717
  readonly presence: 'defaulted';
678
718
  readonly optionalFallback: 'undefined';
719
+ readonly flagKind: 'boolean';
679
720
  }> {
680
721
  return new FlagBuilder(
681
722
  createSchema('boolean', {
@@ -691,6 +732,7 @@ const flag: FlagFactory = {
691
732
  readonly valueType: T[number];
692
733
  readonly presence: 'optional';
693
734
  readonly optionalFallback: 'undefined';
735
+ readonly flagKind: 'enum';
694
736
  }> {
695
737
  return new FlagBuilder(createSchema('enum', { enumValues: values }));
696
738
  },
@@ -701,6 +743,7 @@ const flag: FlagFactory = {
701
743
  readonly valueType: E['valueType'][];
702
744
  readonly presence: 'optional';
703
745
  readonly optionalFallback: 'empty-array';
746
+ readonly flagKind: 'array';
704
747
  }> {
705
748
  return new FlagBuilder(createSchema('array', { elementSchema: element.schema }));
706
749
  },
@@ -709,6 +752,7 @@ const flag: FlagFactory = {
709
752
  readonly valueType: T;
710
753
  readonly presence: 'optional';
711
754
  readonly optionalFallback: 'undefined';
755
+ readonly flagKind: 'custom';
712
756
  }> {
713
757
  return new FlagBuilder(createSchema('custom', { parseFn: parseFn as FlagParseFn<unknown> }));
714
758
  },
@@ -730,6 +774,7 @@ export type {
730
774
  } from './prompt.ts';
731
775
  export { PROMPT_KINDS } from './prompt.ts';
732
776
  export type {
777
+ AllowedPromptConfig,
733
778
  FlagAlias,
734
779
  FlagConfig,
735
780
  FlagFactory,
@@ -43,8 +43,8 @@ const SUPPORTED_RUNTIMES: readonly RuntimeSupportEntry[] = [
43
43
  {
44
44
  runtime: 'bun',
45
45
  displayName: 'Bun',
46
- minimum: '1.3.11',
47
- engineRange: '>=1.3.11',
46
+ minimum: '1.3',
47
+ engineRange: '>=1.3',
48
48
  packageName: '@kjanat/dreamcli',
49
49
  adapterName: 'BunAdapter',
50
50
  },