@optique/inquirer 1.0.0-dev.1616 → 1.0.0-dev.1659
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 +36 -9
- package/dist/index.js +35 -8
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
const __inquirer_prompts = __toESM(require("@inquirer/prompts"));
|
|
25
25
|
const __optique_core_annotations = __toESM(require("@optique/core/annotations"));
|
|
26
|
+
const __optique_core_parser = __toESM(require("@optique/core/parser"));
|
|
26
27
|
const __optique_core_message = __toESM(require("@optique/core/message"));
|
|
27
28
|
|
|
28
29
|
//#region src/index.ts
|
|
@@ -69,7 +70,6 @@ function getPromptFunctions() {
|
|
|
69
70
|
function isExitPromptError(error) {
|
|
70
71
|
return typeof error === "object" && error != null && "name" in error && error.name === "ExitPromptError";
|
|
71
72
|
}
|
|
72
|
-
const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
|
|
73
73
|
function shouldDeferPrompt(parser, state, exec) {
|
|
74
74
|
return typeof parser.shouldDeferCompletion === "function" && parser.shouldDeferCompletion(state, exec) === true;
|
|
75
75
|
}
|
|
@@ -163,6 +163,16 @@ function prompt(parser, config) {
|
|
|
163
163
|
const prototype = Object.getPrototypeOf(cliState);
|
|
164
164
|
return prototype !== Object.prototype && prototype !== null;
|
|
165
165
|
}
|
|
166
|
+
function hasSourceBindingMarker(state) {
|
|
167
|
+
return state != null && typeof state === "object" && "hasCliValue" in state && Object.getOwnPropertySymbols(state).length > 0;
|
|
168
|
+
}
|
|
169
|
+
function shouldCompleteFromSourceBinding(cliState, state) {
|
|
170
|
+
const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState) !== cliState;
|
|
171
|
+
const requiresSourceBindingForAnnotationWrapper = Reflect.get(parser, __optique_core_parser.annotationWrapperRequiresSourceBindingKey) === true;
|
|
172
|
+
const hasNestedSourceBinding = hasSourceBindingMarker(cliState) || Array.isArray(cliState) && cliState.length === 1 && (hasSourceBindingMarker(cliState[0]) || cliState[0] != null && typeof cliState[0] === "object" && __optique_core_annotations.annotationKey in cliState[0]);
|
|
173
|
+
if (cliStateIsInjectedAnnotationWrapper && requiresSourceBindingForAnnotationWrapper) return hasNestedSourceBinding;
|
|
174
|
+
return shouldAttemptInnerCompletion(cliState, state) || hasNestedSourceBinding;
|
|
175
|
+
}
|
|
166
176
|
/**
|
|
167
177
|
* Executes the configured prompt and normalizes its result.
|
|
168
178
|
*
|
|
@@ -309,13 +319,17 @@ function prompt(parser, config) {
|
|
|
309
319
|
$valueType: parser.$valueType,
|
|
310
320
|
$stateType: parser.$stateType,
|
|
311
321
|
priority: parser.priority,
|
|
312
|
-
[inheritParentAnnotationsKey]: true,
|
|
322
|
+
[__optique_core_parser.inheritParentAnnotationsKey]: true,
|
|
313
323
|
usage: parser.usage.length === 1 && parser.usage[0].type === "optional" ? parser.usage : [{
|
|
314
324
|
type: "optional",
|
|
315
325
|
terms: parser.usage
|
|
316
326
|
}],
|
|
317
327
|
leadingNames: parser.leadingNames,
|
|
318
328
|
acceptingAnyToken: parser.acceptingAnyToken,
|
|
329
|
+
getSuggestRuntimeNodes(state, path) {
|
|
330
|
+
const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
|
|
331
|
+
return (0, __optique_core_parser.getDelegatingSuggestRuntimeNodes)(parser, promptedParser, state, path, innerState, "prepend");
|
|
332
|
+
},
|
|
319
333
|
get initialState() {
|
|
320
334
|
return new PromptBindInitialStateClass();
|
|
321
335
|
},
|
|
@@ -326,13 +340,15 @@ function prompt(parser, config) {
|
|
|
326
340
|
...context,
|
|
327
341
|
state: innerState
|
|
328
342
|
} : context;
|
|
343
|
+
const effectiveInnerState = annotations != null && innerState == null && Reflect.get(parser, __optique_core_parser.inheritParentAnnotationsKey) === true ? (0, __optique_core_annotations.injectAnnotations)(innerState, annotations) : innerState;
|
|
329
344
|
const processResult = (result$1) => {
|
|
330
345
|
if (result$1.success) {
|
|
346
|
+
const cliState = annotations != null && result$1.next.state != null && typeof result$1.next.state === "object" && (0, __optique_core_annotations.getAnnotations)(result$1.next.state) !== annotations ? (0, __optique_core_annotations.injectAnnotations)(result$1.next.state, annotations) : result$1.next.state;
|
|
331
347
|
const cliConsumed = result$1.consumed.length > 0;
|
|
332
348
|
const nextState$1 = {
|
|
333
349
|
[promptBindStateKey]: true,
|
|
334
350
|
hasCliValue: cliConsumed,
|
|
335
|
-
cliState
|
|
351
|
+
cliState,
|
|
336
352
|
...annotations != null ? { [__optique_core_annotations.annotationKey]: annotations } : {}
|
|
337
353
|
};
|
|
338
354
|
return {
|
|
@@ -359,7 +375,7 @@ function prompt(parser, config) {
|
|
|
359
375
|
consumed: []
|
|
360
376
|
};
|
|
361
377
|
};
|
|
362
|
-
const result = withAnnotatedInnerState(context.state,
|
|
378
|
+
const result = withAnnotatedInnerState(context.state, effectiveInnerState, (annotatedInnerState) => {
|
|
363
379
|
const innerContext = annotatedInnerState !== context.state ? {
|
|
364
380
|
...context,
|
|
365
381
|
state: annotatedInnerState
|
|
@@ -407,9 +423,7 @@ function prompt(parser, config) {
|
|
|
407
423
|
const decideFromParse = (parseResult) => {
|
|
408
424
|
const consumed = parseResult.success ? parseResult.consumed.length : 0;
|
|
409
425
|
const cliState$1 = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
|
|
410
|
-
const
|
|
411
|
-
const cliStateIsPassthrough = cliState$1 != null && typeof cliState$1 === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState$1) !== cliState$1;
|
|
412
|
-
const isSourceBinding = shouldAttemptInnerCompletion(cliState$1, state) && !cliStateIsPassthrough || hasSourceBindingMarker(cliState$1) || Array.isArray(cliState$1) && cliState$1.length === 1 && (hasSourceBindingMarker(cliState$1[0]) || typeof cliState$1[0] === "object" && cliState$1[0] != null && __optique_core_annotations.annotationKey in cliState$1[0]);
|
|
426
|
+
const isSourceBinding = shouldCompleteFromSourceBinding(cliState$1, state);
|
|
413
427
|
if (isSourceBinding) {
|
|
414
428
|
const cliStateIsInjected = cliState$1 != null && typeof cliState$1 === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState$1) !== cliState$1;
|
|
415
429
|
const handleCompleteResult = (res) => {
|
|
@@ -429,7 +443,7 @@ function prompt(parser, config) {
|
|
|
429
443
|
}
|
|
430
444
|
const cliState = isPromptBindState(state) ? state.cliState : void 0;
|
|
431
445
|
const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState) !== cliState;
|
|
432
|
-
if (
|
|
446
|
+
if (shouldCompleteFromSourceBinding(cliState, state)) {
|
|
433
447
|
const useCompleteResultOrPrompt = (result) => {
|
|
434
448
|
if (result.success && result.value === void 0 && cliStateIsInjectedAnnotationWrapper) return executePrompt();
|
|
435
449
|
return usePromptOrDefer(state, result, exec);
|
|
@@ -448,7 +462,7 @@ function prompt(parser, config) {
|
|
|
448
462
|
return executePrompt();
|
|
449
463
|
},
|
|
450
464
|
suggest: (context, prefix) => {
|
|
451
|
-
const innerState = isPromptBindState(context.state) ? context.state.
|
|
465
|
+
const innerState = isPromptBindState(context.state) ? context.state.cliState === void 0 ? parser.initialState : context.state.cliState : context.state;
|
|
452
466
|
const innerContext = innerState !== context.state ? {
|
|
453
467
|
...context,
|
|
454
468
|
state: innerState
|
|
@@ -464,6 +478,7 @@ function prompt(parser, config) {
|
|
|
464
478
|
return parser.getDocFragments(state, defaultValue);
|
|
465
479
|
}
|
|
466
480
|
};
|
|
481
|
+
(0, __optique_core_parser.defineInheritedAnnotationParser)(promptedParser);
|
|
467
482
|
if ("placeholder" in parser) Object.defineProperty(promptedParser, "placeholder", {
|
|
468
483
|
get() {
|
|
469
484
|
try {
|
|
@@ -480,6 +495,18 @@ function prompt(parser, config) {
|
|
|
480
495
|
configurable: true,
|
|
481
496
|
enumerable: false
|
|
482
497
|
});
|
|
498
|
+
const dependencyMetadata = (0, __optique_core_parser.composeWrappedSourceMetadata)(parser.dependencyMetadata, (source) => ({
|
|
499
|
+
...source,
|
|
500
|
+
extractSourceValue: (state) => {
|
|
501
|
+
if (!isPromptBindState(state)) return source.extractSourceValue(state);
|
|
502
|
+
return source.extractSourceValue(state.cliState ?? state);
|
|
503
|
+
}
|
|
504
|
+
}));
|
|
505
|
+
if (dependencyMetadata != null) Object.defineProperty(promptedParser, "dependencyMetadata", {
|
|
506
|
+
value: dependencyMetadata,
|
|
507
|
+
configurable: true,
|
|
508
|
+
enumerable: false
|
|
509
|
+
});
|
|
483
510
|
return promptedParser;
|
|
484
511
|
}
|
|
485
512
|
/** Normalize choices to the format Inquirer.js expects. */
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Separator, checkbox, confirm, editor, expand, input, number, password, rawlist, select } from "@inquirer/prompts";
|
|
2
2
|
import { annotationKey, getAnnotations, inheritAnnotations, injectAnnotations, unwrapInjectedAnnotationWrapper } from "@optique/core/annotations";
|
|
3
|
+
import { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, defineInheritedAnnotationParser, getDelegatingSuggestRuntimeNodes, inheritParentAnnotationsKey } from "@optique/core/parser";
|
|
3
4
|
import { message } from "@optique/core/message";
|
|
4
5
|
|
|
5
6
|
//#region src/index.ts
|
|
@@ -46,7 +47,6 @@ function getPromptFunctions() {
|
|
|
46
47
|
function isExitPromptError(error) {
|
|
47
48
|
return typeof error === "object" && error != null && "name" in error && error.name === "ExitPromptError";
|
|
48
49
|
}
|
|
49
|
-
const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
|
|
50
50
|
function shouldDeferPrompt(parser, state, exec) {
|
|
51
51
|
return typeof parser.shouldDeferCompletion === "function" && parser.shouldDeferCompletion(state, exec) === true;
|
|
52
52
|
}
|
|
@@ -140,6 +140,16 @@ function prompt(parser, config) {
|
|
|
140
140
|
const prototype = Object.getPrototypeOf(cliState);
|
|
141
141
|
return prototype !== Object.prototype && prototype !== null;
|
|
142
142
|
}
|
|
143
|
+
function hasSourceBindingMarker(state) {
|
|
144
|
+
return state != null && typeof state === "object" && "hasCliValue" in state && Object.getOwnPropertySymbols(state).length > 0;
|
|
145
|
+
}
|
|
146
|
+
function shouldCompleteFromSourceBinding(cliState, state) {
|
|
147
|
+
const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationWrapper(cliState) !== cliState;
|
|
148
|
+
const requiresSourceBindingForAnnotationWrapper = Reflect.get(parser, annotationWrapperRequiresSourceBindingKey) === true;
|
|
149
|
+
const hasNestedSourceBinding = hasSourceBindingMarker(cliState) || Array.isArray(cliState) && cliState.length === 1 && (hasSourceBindingMarker(cliState[0]) || cliState[0] != null && typeof cliState[0] === "object" && annotationKey in cliState[0]);
|
|
150
|
+
if (cliStateIsInjectedAnnotationWrapper && requiresSourceBindingForAnnotationWrapper) return hasNestedSourceBinding;
|
|
151
|
+
return shouldAttemptInnerCompletion(cliState, state) || hasNestedSourceBinding;
|
|
152
|
+
}
|
|
143
153
|
/**
|
|
144
154
|
* Executes the configured prompt and normalizes its result.
|
|
145
155
|
*
|
|
@@ -293,6 +303,10 @@ function prompt(parser, config) {
|
|
|
293
303
|
}],
|
|
294
304
|
leadingNames: parser.leadingNames,
|
|
295
305
|
acceptingAnyToken: parser.acceptingAnyToken,
|
|
306
|
+
getSuggestRuntimeNodes(state, path) {
|
|
307
|
+
const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
|
|
308
|
+
return getDelegatingSuggestRuntimeNodes(parser, promptedParser, state, path, innerState, "prepend");
|
|
309
|
+
},
|
|
296
310
|
get initialState() {
|
|
297
311
|
return new PromptBindInitialStateClass();
|
|
298
312
|
},
|
|
@@ -303,13 +317,15 @@ function prompt(parser, config) {
|
|
|
303
317
|
...context,
|
|
304
318
|
state: innerState
|
|
305
319
|
} : context;
|
|
320
|
+
const effectiveInnerState = annotations != null && innerState == null && Reflect.get(parser, inheritParentAnnotationsKey) === true ? injectAnnotations(innerState, annotations) : innerState;
|
|
306
321
|
const processResult = (result$1) => {
|
|
307
322
|
if (result$1.success) {
|
|
323
|
+
const cliState = annotations != null && result$1.next.state != null && typeof result$1.next.state === "object" && getAnnotations(result$1.next.state) !== annotations ? injectAnnotations(result$1.next.state, annotations) : result$1.next.state;
|
|
308
324
|
const cliConsumed = result$1.consumed.length > 0;
|
|
309
325
|
const nextState$1 = {
|
|
310
326
|
[promptBindStateKey]: true,
|
|
311
327
|
hasCliValue: cliConsumed,
|
|
312
|
-
cliState
|
|
328
|
+
cliState,
|
|
313
329
|
...annotations != null ? { [annotationKey]: annotations } : {}
|
|
314
330
|
};
|
|
315
331
|
return {
|
|
@@ -336,7 +352,7 @@ function prompt(parser, config) {
|
|
|
336
352
|
consumed: []
|
|
337
353
|
};
|
|
338
354
|
};
|
|
339
|
-
const result = withAnnotatedInnerState(context.state,
|
|
355
|
+
const result = withAnnotatedInnerState(context.state, effectiveInnerState, (annotatedInnerState) => {
|
|
340
356
|
const innerContext = annotatedInnerState !== context.state ? {
|
|
341
357
|
...context,
|
|
342
358
|
state: annotatedInnerState
|
|
@@ -384,9 +400,7 @@ function prompt(parser, config) {
|
|
|
384
400
|
const decideFromParse = (parseResult) => {
|
|
385
401
|
const consumed = parseResult.success ? parseResult.consumed.length : 0;
|
|
386
402
|
const cliState$1 = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
|
|
387
|
-
const
|
|
388
|
-
const cliStateIsPassthrough = cliState$1 != null && typeof cliState$1 === "object" && unwrapInjectedAnnotationWrapper(cliState$1) !== cliState$1;
|
|
389
|
-
const isSourceBinding = shouldAttemptInnerCompletion(cliState$1, state) && !cliStateIsPassthrough || hasSourceBindingMarker(cliState$1) || Array.isArray(cliState$1) && cliState$1.length === 1 && (hasSourceBindingMarker(cliState$1[0]) || typeof cliState$1[0] === "object" && cliState$1[0] != null && annotationKey in cliState$1[0]);
|
|
403
|
+
const isSourceBinding = shouldCompleteFromSourceBinding(cliState$1, state);
|
|
390
404
|
if (isSourceBinding) {
|
|
391
405
|
const cliStateIsInjected = cliState$1 != null && typeof cliState$1 === "object" && unwrapInjectedAnnotationWrapper(cliState$1) !== cliState$1;
|
|
392
406
|
const handleCompleteResult = (res) => {
|
|
@@ -406,7 +420,7 @@ function prompt(parser, config) {
|
|
|
406
420
|
}
|
|
407
421
|
const cliState = isPromptBindState(state) ? state.cliState : void 0;
|
|
408
422
|
const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationWrapper(cliState) !== cliState;
|
|
409
|
-
if (
|
|
423
|
+
if (shouldCompleteFromSourceBinding(cliState, state)) {
|
|
410
424
|
const useCompleteResultOrPrompt = (result) => {
|
|
411
425
|
if (result.success && result.value === void 0 && cliStateIsInjectedAnnotationWrapper) return executePrompt();
|
|
412
426
|
return usePromptOrDefer(state, result, exec);
|
|
@@ -425,7 +439,7 @@ function prompt(parser, config) {
|
|
|
425
439
|
return executePrompt();
|
|
426
440
|
},
|
|
427
441
|
suggest: (context, prefix) => {
|
|
428
|
-
const innerState = isPromptBindState(context.state) ? context.state.
|
|
442
|
+
const innerState = isPromptBindState(context.state) ? context.state.cliState === void 0 ? parser.initialState : context.state.cliState : context.state;
|
|
429
443
|
const innerContext = innerState !== context.state ? {
|
|
430
444
|
...context,
|
|
431
445
|
state: innerState
|
|
@@ -441,6 +455,7 @@ function prompt(parser, config) {
|
|
|
441
455
|
return parser.getDocFragments(state, defaultValue);
|
|
442
456
|
}
|
|
443
457
|
};
|
|
458
|
+
defineInheritedAnnotationParser(promptedParser);
|
|
444
459
|
if ("placeholder" in parser) Object.defineProperty(promptedParser, "placeholder", {
|
|
445
460
|
get() {
|
|
446
461
|
try {
|
|
@@ -457,6 +472,18 @@ function prompt(parser, config) {
|
|
|
457
472
|
configurable: true,
|
|
458
473
|
enumerable: false
|
|
459
474
|
});
|
|
475
|
+
const dependencyMetadata = composeWrappedSourceMetadata(parser.dependencyMetadata, (source) => ({
|
|
476
|
+
...source,
|
|
477
|
+
extractSourceValue: (state) => {
|
|
478
|
+
if (!isPromptBindState(state)) return source.extractSourceValue(state);
|
|
479
|
+
return source.extractSourceValue(state.cliState ?? state);
|
|
480
|
+
}
|
|
481
|
+
}));
|
|
482
|
+
if (dependencyMetadata != null) Object.defineProperty(promptedParser, "dependencyMetadata", {
|
|
483
|
+
value: dependencyMetadata,
|
|
484
|
+
configurable: true,
|
|
485
|
+
enumerable: false
|
|
486
|
+
});
|
|
460
487
|
return promptedParser;
|
|
461
488
|
}
|
|
462
489
|
/** Normalize choices to the format Inquirer.js expects. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/inquirer",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.1659+94dcbc28",
|
|
4
4
|
"description": "Interactive prompt support for Optique via Inquirer.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"sideEffects": false,
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@inquirer/prompts": "^8.3.0",
|
|
59
|
-
"@optique/core": "1.0.0-dev.
|
|
59
|
+
"@optique/core": "1.0.0-dev.1659+94dcbc28"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/node": "^20.19.9",
|
|
63
63
|
"tsdown": "^0.13.0",
|
|
64
64
|
"typescript": "^5.8.3",
|
|
65
|
-
"@optique/env": "1.0.0-dev.
|
|
65
|
+
"@optique/env": "1.0.0-dev.1659+94dcbc28"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "tsdown",
|