@optique/prompt 1.3.0-dev.2351 → 1.3.0-dev.2353

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/index.cjs CHANGED
@@ -108,7 +108,11 @@ function createPromptAdapter(adapter) {
108
108
  if (cliStateIsInjectedAnnotationWrapper && requiresSourceBindingForAnnotationWrapper) return hasNestedSourceBinding;
109
109
  return shouldAttemptInnerCompletion(cliState, state) || hasNestedSourceBinding;
110
110
  }
111
- function executePrompt() {
111
+ async function executePrompt() {
112
+ if (config.when != null && !await config.when()) return {
113
+ success: true,
114
+ value: config.otherwise
115
+ };
112
116
  return adapter.execute(config);
113
117
  }
114
118
  const parserInheritsAnnotations = (0, __optique_core_extension.getTraits)(parser).inheritsAnnotations === true;
package/dist/index.d.cts CHANGED
@@ -4,6 +4,24 @@ import { ValueParserResult } from "@optique/core/valueparser";
4
4
 
5
5
  //#region src/index.d.ts
6
6
 
7
+ /**
8
+ * Controls whether a prompt fallback runs at runtime.
9
+ *
10
+ * When `when` returns `false`, the prompt adapter is skipped and `otherwise`
11
+ * is returned. The condition runs only when parsing reaches the prompt
12
+ * fallback, after CLI values and other configured value sources have been
13
+ * exhausted.
14
+ *
15
+ * @typeParam TValue Value type produced by the wrapped parser.
16
+ * @since 1.3.0
17
+ */
18
+ type PromptCondition<TValue> = {
19
+ readonly when?: never;
20
+ readonly otherwise?: never;
21
+ } | {
22
+ readonly when: () => boolean | Promise<boolean>;
23
+ readonly otherwise: NoInfer<TValue>;
24
+ };
7
25
  /**
8
26
  * Prompt adapter used by {@link createPromptAdapter}.
9
27
  *
@@ -53,6 +71,6 @@ interface PromptAdapter<TConfig> {
53
71
  * parser.
54
72
  * @since 1.2.0
55
73
  */
56
- declare function createPromptAdapter<TConfig>(adapter: PromptAdapter<TConfig>): <M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: TConfig) => FluentParser<"async", TValue, TState>;
74
+ declare function createPromptAdapter<TConfig>(adapter: PromptAdapter<TConfig>): <M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: TConfig & PromptCondition<TValue>) => FluentParser<"async", TValue, TState>;
57
75
  //#endregion
58
- export { PromptAdapter, createPromptAdapter };
76
+ export { PromptAdapter, PromptCondition, createPromptAdapter };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,24 @@ import { ValueParserResult } from "@optique/core/valueparser";
4
4
 
5
5
  //#region src/index.d.ts
6
6
 
7
+ /**
8
+ * Controls whether a prompt fallback runs at runtime.
9
+ *
10
+ * When `when` returns `false`, the prompt adapter is skipped and `otherwise`
11
+ * is returned. The condition runs only when parsing reaches the prompt
12
+ * fallback, after CLI values and other configured value sources have been
13
+ * exhausted.
14
+ *
15
+ * @typeParam TValue Value type produced by the wrapped parser.
16
+ * @since 1.3.0
17
+ */
18
+ type PromptCondition<TValue> = {
19
+ readonly when?: never;
20
+ readonly otherwise?: never;
21
+ } | {
22
+ readonly when: () => boolean | Promise<boolean>;
23
+ readonly otherwise: NoInfer<TValue>;
24
+ };
7
25
  /**
8
26
  * Prompt adapter used by {@link createPromptAdapter}.
9
27
  *
@@ -53,6 +71,6 @@ interface PromptAdapter<TConfig> {
53
71
  * parser.
54
72
  * @since 1.2.0
55
73
  */
56
- declare function createPromptAdapter<TConfig>(adapter: PromptAdapter<TConfig>): <M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: TConfig) => FluentParser<"async", TValue, TState>;
74
+ declare function createPromptAdapter<TConfig>(adapter: PromptAdapter<TConfig>): <M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: TConfig & PromptCondition<TValue>) => FluentParser<"async", TValue, TState>;
57
75
  //#endregion
58
- export { PromptAdapter, createPromptAdapter };
76
+ export { PromptAdapter, PromptCondition, createPromptAdapter };
package/dist/index.js CHANGED
@@ -85,7 +85,11 @@ function createPromptAdapter(adapter) {
85
85
  if (cliStateIsInjectedAnnotationWrapper && requiresSourceBindingForAnnotationWrapper) return hasNestedSourceBinding;
86
86
  return shouldAttemptInnerCompletion(cliState, state) || hasNestedSourceBinding;
87
87
  }
88
- function executePrompt() {
88
+ async function executePrompt() {
89
+ if (config.when != null && !await config.when()) return {
90
+ success: true,
91
+ value: config.otherwise
92
+ };
89
93
  return adapter.execute(config);
90
94
  }
91
95
  const parserInheritsAnnotations = getTraits(parser).inheritsAnnotations === true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/prompt",
3
- "version": "1.3.0-dev.2351",
3
+ "version": "1.3.0-dev.2353",
4
4
  "description": "Generic prompt adapter support for Optique",
5
5
  "keywords": [
6
6
  "CLI",
@@ -60,16 +60,16 @@
60
60
  },
61
61
  "sideEffects": false,
62
62
  "dependencies": {
63
- "@optique/core": "1.3.0-dev.2351+2298bec5"
63
+ "@optique/core": "1.3.0-dev.2353+1e07f6ab"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/node": "^24.0.0",
67
67
  "fast-check": "^4.7.0",
68
68
  "tsdown": "^0.13.0",
69
69
  "typescript": "^5.8.3",
70
- "@optique/env": "1.3.0-dev.2351+2298bec5",
71
- "@optique/config": "1.3.0-dev.2351+2298bec5",
72
- "@optique/run": "1.3.0-dev.2351+2298bec5"
70
+ "@optique/config": "1.3.0-dev.2353+1e07f6ab",
71
+ "@optique/run": "1.3.0-dev.2353+1e07f6ab",
72
+ "@optique/env": "1.3.0-dev.2353+1e07f6ab"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "tsdown",