@optique/inquirer 1.0.0-dev.1658 → 1.0.0-dev.1661

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
@@ -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,7 +319,7 @@ 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
@@ -318,13 +328,7 @@ function prompt(parser, config) {
318
328
  acceptingAnyToken: parser.acceptingAnyToken,
319
329
  getSuggestRuntimeNodes(state, path) {
320
330
  const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
321
- const innerNodes = parser.getSuggestRuntimeNodes?.(innerState, path) ?? [];
322
- if (promptedParser.dependencyMetadata?.source != null) return [{
323
- path,
324
- parser: promptedParser,
325
- state
326
- }, ...innerNodes];
327
- return innerNodes;
331
+ return (0, __optique_core_parser.getDelegatingSuggestRuntimeNodes)(parser, promptedParser, state, path, innerState, "prepend");
328
332
  },
329
333
  get initialState() {
330
334
  return new PromptBindInitialStateClass();
@@ -336,14 +340,15 @@ function prompt(parser, config) {
336
340
  ...context,
337
341
  state: innerState
338
342
  } : context;
339
- const effectiveInnerState = annotations != null && innerState == null && Reflect.get(parser, inheritParentAnnotationsKey) === true ? (0, __optique_core_annotations.injectAnnotations)(innerState, annotations) : innerState;
343
+ const effectiveInnerState = annotations != null && innerState == null && Reflect.get(parser, __optique_core_parser.inheritParentAnnotationsKey) === true ? (0, __optique_core_annotations.injectAnnotations)(innerState, annotations) : innerState;
340
344
  const processResult = (result$1) => {
341
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;
342
347
  const cliConsumed = result$1.consumed.length > 0;
343
348
  const nextState$1 = {
344
349
  [promptBindStateKey]: true,
345
350
  hasCliValue: cliConsumed,
346
- cliState: result$1.next.state,
351
+ cliState,
347
352
  ...annotations != null ? { [__optique_core_annotations.annotationKey]: annotations } : {}
348
353
  };
349
354
  return {
@@ -418,9 +423,7 @@ function prompt(parser, config) {
418
423
  const decideFromParse = (parseResult) => {
419
424
  const consumed = parseResult.success ? parseResult.consumed.length : 0;
420
425
  const cliState$1 = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
421
- const hasSourceBindingMarker = (s) => s != null && typeof s === "object" && "hasCliValue" in s && Object.getOwnPropertySymbols(s).length > 0;
422
- const cliStateIsPassthrough = cliState$1 != null && typeof cliState$1 === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState$1) !== cliState$1;
423
- 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);
424
427
  if (isSourceBinding) {
425
428
  const cliStateIsInjected = cliState$1 != null && typeof cliState$1 === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState$1) !== cliState$1;
426
429
  const handleCompleteResult = (res) => {
@@ -440,7 +443,7 @@ function prompt(parser, config) {
440
443
  }
441
444
  const cliState = isPromptBindState(state) ? state.cliState : void 0;
442
445
  const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState) !== cliState;
443
- if (shouldAttemptInnerCompletion(cliState, state)) {
446
+ if (shouldCompleteFromSourceBinding(cliState, state)) {
444
447
  const useCompleteResultOrPrompt = (result) => {
445
448
  if (result.success && result.value === void 0 && cliStateIsInjectedAnnotationWrapper) return executePrompt();
446
449
  return usePromptOrDefer(state, result, exec);
@@ -475,6 +478,7 @@ function prompt(parser, config) {
475
478
  return parser.getDocFragments(state, defaultValue);
476
479
  }
477
480
  };
481
+ (0, __optique_core_parser.defineInheritedAnnotationParser)(promptedParser);
478
482
  if ("placeholder" in parser) Object.defineProperty(promptedParser, "placeholder", {
479
483
  get() {
480
484
  try {
@@ -491,18 +495,15 @@ function prompt(parser, config) {
491
495
  configurable: true,
492
496
  enumerable: false
493
497
  });
494
- const dependencyMetadata = parser.dependencyMetadata;
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
+ }));
495
505
  if (dependencyMetadata != null) Object.defineProperty(promptedParser, "dependencyMetadata", {
496
- value: dependencyMetadata.source == null ? dependencyMetadata : {
497
- ...dependencyMetadata,
498
- source: {
499
- ...dependencyMetadata.source,
500
- extractSourceValue: (state) => {
501
- if (!isPromptBindState(state)) return dependencyMetadata.source?.extractSourceValue(state);
502
- return dependencyMetadata.source?.extractSourceValue(state.cliState ?? state);
503
- }
504
- }
505
- },
506
+ value: dependencyMetadata,
506
507
  configurable: true,
507
508
  enumerable: false
508
509
  });
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
  *
@@ -295,13 +305,7 @@ function prompt(parser, config) {
295
305
  acceptingAnyToken: parser.acceptingAnyToken,
296
306
  getSuggestRuntimeNodes(state, path) {
297
307
  const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
298
- const innerNodes = parser.getSuggestRuntimeNodes?.(innerState, path) ?? [];
299
- if (promptedParser.dependencyMetadata?.source != null) return [{
300
- path,
301
- parser: promptedParser,
302
- state
303
- }, ...innerNodes];
304
- return innerNodes;
308
+ return getDelegatingSuggestRuntimeNodes(parser, promptedParser, state, path, innerState, "prepend");
305
309
  },
306
310
  get initialState() {
307
311
  return new PromptBindInitialStateClass();
@@ -316,11 +320,12 @@ function prompt(parser, config) {
316
320
  const effectiveInnerState = annotations != null && innerState == null && Reflect.get(parser, inheritParentAnnotationsKey) === true ? injectAnnotations(innerState, annotations) : innerState;
317
321
  const processResult = (result$1) => {
318
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;
319
324
  const cliConsumed = result$1.consumed.length > 0;
320
325
  const nextState$1 = {
321
326
  [promptBindStateKey]: true,
322
327
  hasCliValue: cliConsumed,
323
- cliState: result$1.next.state,
328
+ cliState,
324
329
  ...annotations != null ? { [annotationKey]: annotations } : {}
325
330
  };
326
331
  return {
@@ -395,9 +400,7 @@ function prompt(parser, config) {
395
400
  const decideFromParse = (parseResult) => {
396
401
  const consumed = parseResult.success ? parseResult.consumed.length : 0;
397
402
  const cliState$1 = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
398
- const hasSourceBindingMarker = (s) => s != null && typeof s === "object" && "hasCliValue" in s && Object.getOwnPropertySymbols(s).length > 0;
399
- const cliStateIsPassthrough = cliState$1 != null && typeof cliState$1 === "object" && unwrapInjectedAnnotationWrapper(cliState$1) !== cliState$1;
400
- 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);
401
404
  if (isSourceBinding) {
402
405
  const cliStateIsInjected = cliState$1 != null && typeof cliState$1 === "object" && unwrapInjectedAnnotationWrapper(cliState$1) !== cliState$1;
403
406
  const handleCompleteResult = (res) => {
@@ -417,7 +420,7 @@ function prompt(parser, config) {
417
420
  }
418
421
  const cliState = isPromptBindState(state) ? state.cliState : void 0;
419
422
  const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationWrapper(cliState) !== cliState;
420
- if (shouldAttemptInnerCompletion(cliState, state)) {
423
+ if (shouldCompleteFromSourceBinding(cliState, state)) {
421
424
  const useCompleteResultOrPrompt = (result) => {
422
425
  if (result.success && result.value === void 0 && cliStateIsInjectedAnnotationWrapper) return executePrompt();
423
426
  return usePromptOrDefer(state, result, exec);
@@ -452,6 +455,7 @@ function prompt(parser, config) {
452
455
  return parser.getDocFragments(state, defaultValue);
453
456
  }
454
457
  };
458
+ defineInheritedAnnotationParser(promptedParser);
455
459
  if ("placeholder" in parser) Object.defineProperty(promptedParser, "placeholder", {
456
460
  get() {
457
461
  try {
@@ -468,18 +472,15 @@ function prompt(parser, config) {
468
472
  configurable: true,
469
473
  enumerable: false
470
474
  });
471
- const dependencyMetadata = parser.dependencyMetadata;
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
+ }));
472
482
  if (dependencyMetadata != null) Object.defineProperty(promptedParser, "dependencyMetadata", {
473
- value: dependencyMetadata.source == null ? dependencyMetadata : {
474
- ...dependencyMetadata,
475
- source: {
476
- ...dependencyMetadata.source,
477
- extractSourceValue: (state) => {
478
- if (!isPromptBindState(state)) return dependencyMetadata.source?.extractSourceValue(state);
479
- return dependencyMetadata.source?.extractSourceValue(state.cliState ?? state);
480
- }
481
- }
482
- },
483
+ value: dependencyMetadata,
483
484
  configurable: true,
484
485
  enumerable: false
485
486
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/inquirer",
3
- "version": "1.0.0-dev.1658+b57e115b",
3
+ "version": "1.0.0-dev.1661+6fc17d4f",
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.1658+b57e115b"
59
+ "@optique/core": "1.0.0-dev.1661+6fc17d4f"
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.1658+b57e115b"
65
+ "@optique/env": "1.0.0-dev.1661+6fc17d4f"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsdown",