@optique/inquirer 1.0.0-dev.1734 → 1.0.0-dev.1737

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
@@ -25,7 +25,6 @@ const __inquirer_prompts = __toESM(require("@inquirer/prompts"));
25
25
  const __optique_core_annotations = __toESM(require("@optique/core/annotations"));
26
26
  const __optique_core_parser = __toESM(require("@optique/core/parser"));
27
27
  const __optique_core_message = __toESM(require("@optique/core/message"));
28
- const __optique_core_modifiers = __toESM(require("@optique/core/modifiers"));
29
28
 
30
29
  //#region src/index.ts
31
30
  const promptFunctionsOverrideSymbol = Symbol.for("@optique/inquirer/prompt-functions");
@@ -149,13 +148,8 @@ function prompt(parser, config) {
149
148
  return value != null && typeof value === "object" && promptBindStateKey in value;
150
149
  }
151
150
  const cfg = config;
152
- const PromptBindInitialStateClass = class {
153
- [promptBindStateKey] = true;
154
- hasCliValue = false;
155
- };
156
- const promptCache = /* @__PURE__ */ new WeakMap();
157
151
  function shouldAttemptInnerCompletion(cliState, state) {
158
- if (cliState == null || cliState instanceof PromptBindInitialStateClass) return false;
152
+ if (cliState == null) return false;
159
153
  const cliStateHasAnnotations = typeof cliState === "object" && __optique_core_annotations.annotationKey in cliState;
160
154
  if (cliStateHasAnnotations) return true;
161
155
  if ((0, __optique_core_annotations.getAnnotations)(state) == null || typeof cliState !== "object") return false;
@@ -306,22 +300,12 @@ function prompt(parser, config) {
306
300
  const result = await executePromptRaw();
307
301
  return validatePromptedValue(result);
308
302
  }
309
- function usePromptOrDefer(state, result, exec) {
310
- if (result.success) return Promise.resolve(result);
311
- if (!shouldDeferPrompt(parser, state, exec)) return executePrompt();
312
- let ph;
313
- try {
314
- ph = "placeholder" in parser ? parser.placeholder : void 0;
315
- } catch {}
316
- return Promise.resolve(deferredPromptResult(ph));
317
- }
318
303
  const promptedParser = {
319
304
  $mode: "async",
320
305
  $valueType: parser.$valueType,
321
306
  $stateType: parser.$stateType,
322
307
  priority: parser.priority,
323
308
  [__optique_core_parser.inheritParentAnnotationsKey]: true,
324
- [__optique_core_modifiers.optionalStyleWrapperKey]: true,
325
309
  usage: parser.usage.length === 1 && parser.usage[0].type === "optional" ? parser.usage : [{
326
310
  type: "optional",
327
311
  terms: parser.usage
@@ -332,8 +316,9 @@ function prompt(parser, config) {
332
316
  const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
333
317
  return (0, __optique_core_parser.getDelegatingSuggestRuntimeNodes)(parser, promptedParser, state, path, innerState, "prepend");
334
318
  },
335
- get initialState() {
336
- return new PromptBindInitialStateClass();
319
+ initialState: {
320
+ [promptBindStateKey]: true,
321
+ hasCliValue: false
337
322
  },
338
323
  parse: (context) => {
339
324
  const annotations = (0, __optique_core_annotations.getAnnotations)(context.state);
@@ -394,75 +379,66 @@ function prompt(parser, config) {
394
379
  if (r instanceof Promise) return r;
395
380
  return Promise.resolve(r);
396
381
  }
397
- if (state instanceof PromptBindInitialStateClass) {
398
- if (promptCache.has(state)) {
399
- const cached = promptCache.get(state);
400
- promptCache.delete(state);
401
- return cached;
382
+ const isProbe = exec?.phase === "parse";
383
+ const annotations = (0, __optique_core_annotations.getAnnotations)(state);
384
+ const innerInitialState = parser.initialState;
385
+ const effectiveInitialState = annotations != null && innerInitialState == null ? (0, __optique_core_annotations.injectAnnotations)(innerInitialState, annotations) : innerInitialState;
386
+ const finalizePrompt = () => {
387
+ if (shouldDeferPrompt(parser, state, exec)) {
388
+ let ph;
389
+ try {
390
+ ph = "placeholder" in parser ? parser.placeholder : void 0;
391
+ } catch {}
392
+ return Promise.resolve(deferredPromptResult(ph));
402
393
  }
403
- const hasDeferHook = typeof parser.shouldDeferCompletion === "function";
404
- const annotations = (0, __optique_core_annotations.getAnnotations)(state);
405
- const innerInitialState = parser.initialState;
406
- const effectiveInitialState = annotations != null && innerInitialState == null ? (0, __optique_core_annotations.injectAnnotations)(innerInitialState, annotations) : innerInitialState;
407
- if (hasDeferHook) {
408
- const annotatedR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
409
- const usePromptOrDeferSentinel = (res) => {
410
- if (res.success && res.value === void 0) return usePromptOrDefer(state, {
411
- success: false,
412
- error: []
413
- }, exec);
414
- return usePromptOrDefer(state, res, exec);
415
- };
416
- const cachedResult$1 = annotatedR instanceof Promise ? annotatedR.then(usePromptOrDeferSentinel) : usePromptOrDeferSentinel(annotatedR);
417
- promptCache.set(state, cachedResult$1);
418
- return cachedResult$1;
394
+ if (isProbe) {
395
+ let ph;
396
+ try {
397
+ ph = "placeholder" in parser ? parser.placeholder : void 0;
398
+ } catch {}
399
+ return Promise.resolve({
400
+ success: true,
401
+ value: ph
402
+ });
419
403
  }
404
+ return executePrompt();
405
+ };
406
+ const hasDeferHook = typeof parser.shouldDeferCompletion === "function";
407
+ const decideFromParse = (parseResult) => {
408
+ const consumed = parseResult.success ? parseResult.consumed.length : 0;
409
+ const cliState = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
410
+ const cliStateIsInjected = cliState != null && typeof cliState === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState) !== cliState;
411
+ const isSourceBinding = shouldCompleteFromSourceBinding(cliState, state);
412
+ if (!isSourceBinding) return finalizePrompt();
413
+ const completeState = parseResult.success ? parseResult.next.state : effectiveInitialState;
414
+ const innerR = parser.complete(completeState, exec);
415
+ const handleCompleteResult = (res) => {
416
+ if (res.success && res.value === void 0 && cliStateIsInjected) return finalizePrompt();
417
+ if (!res.success) return finalizePrompt();
418
+ return Promise.resolve(res);
419
+ };
420
+ if (innerR instanceof Promise) return innerR.then(handleCompleteResult);
421
+ return handleCompleteResult(innerR);
422
+ };
423
+ return hasDeferHook ? (() => {
424
+ const innerR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
425
+ const handleDeferHookResult = (res) => {
426
+ if (res.success && res.value === void 0) return finalizePrompt();
427
+ if (!res.success) return finalizePrompt();
428
+ return Promise.resolve(res);
429
+ };
430
+ if (innerR instanceof Promise) return innerR.then(handleDeferHookResult);
431
+ return handleDeferHookResult(innerR);
432
+ })() : (() => {
420
433
  const simParseR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedState) => parser.parse({
421
434
  buffer: [],
422
435
  state: annotatedState,
423
436
  optionsTerminated: false,
424
437
  usage: parser.usage
425
438
  }));
426
- const decideFromParse = (parseResult) => {
427
- const consumed = parseResult.success ? parseResult.consumed.length : 0;
428
- const cliState$1 = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
429
- const isSourceBinding = shouldCompleteFromSourceBinding(cliState$1, state);
430
- if (isSourceBinding) {
431
- const cliStateIsInjected = cliState$1 != null && typeof cliState$1 === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState$1) !== cliState$1;
432
- const handleCompleteResult = (res) => {
433
- if (res.success && res.value === void 0 && cliStateIsInjected) return executePrompt();
434
- return usePromptOrDefer(state, res, exec);
435
- };
436
- const completeState = parseResult.success ? parseResult.next.state : effectiveInitialState;
437
- const completeR = parser.complete(completeState, exec);
438
- if (completeR instanceof Promise) return completeR.then(handleCompleteResult);
439
- return handleCompleteResult(completeR);
440
- }
441
- return executePrompt();
442
- };
443
- const cachedResult = simParseR instanceof Promise ? simParseR.then(decideFromParse) : decideFromParse(simParseR);
444
- promptCache.set(state, cachedResult);
445
- return cachedResult;
446
- }
447
- const cliState = isPromptBindState(state) ? state.cliState : void 0;
448
- const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState) !== cliState;
449
- if (shouldCompleteFromSourceBinding(cliState, state)) {
450
- const useCompleteResultOrPrompt = (result) => {
451
- if (result.success && result.value === void 0 && cliStateIsInjectedAnnotationWrapper) return executePrompt();
452
- return usePromptOrDefer(state, result, exec);
453
- };
454
- const r = withAnnotatedInnerState(state, cliState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
455
- if (r instanceof Promise) return r.then(useCompleteResultOrPrompt);
456
- return useCompleteResultOrPrompt(r);
457
- }
458
- if (shouldDeferPrompt(parser, state, exec)) {
459
- let ph;
460
- try {
461
- ph = "placeholder" in parser ? parser.placeholder : void 0;
462
- } catch {}
463
- return Promise.resolve(deferredPromptResult(ph));
464
- }
465
- return executePrompt();
439
+ if (simParseR instanceof Promise) return simParseR.then(decideFromParse);
440
+ return decideFromParse(simParseR);
441
+ })();
466
442
  },
467
443
  suggest: (context, prefix) => {
468
444
  const innerState = isPromptBindState(context.state) ? context.state.cliState === void 0 ? parser.initialState : context.state.cliState : context.state;
package/dist/index.js CHANGED
@@ -2,7 +2,6 @@ import { Separator, checkbox, confirm, editor, expand, input, number, password,
2
2
  import { annotationKey, getAnnotations, inheritAnnotations, injectAnnotations, unwrapInjectedAnnotationWrapper } from "@optique/core/annotations";
3
3
  import { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, defineInheritedAnnotationParser, getDelegatingSuggestRuntimeNodes, inheritParentAnnotationsKey } from "@optique/core/parser";
4
4
  import { message } from "@optique/core/message";
5
- import { optionalStyleWrapperKey } from "@optique/core/modifiers";
6
5
 
7
6
  //#region src/index.ts
8
7
  const promptFunctionsOverrideSymbol = Symbol.for("@optique/inquirer/prompt-functions");
@@ -126,13 +125,8 @@ function prompt(parser, config) {
126
125
  return value != null && typeof value === "object" && promptBindStateKey in value;
127
126
  }
128
127
  const cfg = config;
129
- const PromptBindInitialStateClass = class {
130
- [promptBindStateKey] = true;
131
- hasCliValue = false;
132
- };
133
- const promptCache = /* @__PURE__ */ new WeakMap();
134
128
  function shouldAttemptInnerCompletion(cliState, state) {
135
- if (cliState == null || cliState instanceof PromptBindInitialStateClass) return false;
129
+ if (cliState == null) return false;
136
130
  const cliStateHasAnnotations = typeof cliState === "object" && annotationKey in cliState;
137
131
  if (cliStateHasAnnotations) return true;
138
132
  if (getAnnotations(state) == null || typeof cliState !== "object") return false;
@@ -283,22 +277,12 @@ function prompt(parser, config) {
283
277
  const result = await executePromptRaw();
284
278
  return validatePromptedValue(result);
285
279
  }
286
- function usePromptOrDefer(state, result, exec) {
287
- if (result.success) return Promise.resolve(result);
288
- if (!shouldDeferPrompt(parser, state, exec)) return executePrompt();
289
- let ph;
290
- try {
291
- ph = "placeholder" in parser ? parser.placeholder : void 0;
292
- } catch {}
293
- return Promise.resolve(deferredPromptResult(ph));
294
- }
295
280
  const promptedParser = {
296
281
  $mode: "async",
297
282
  $valueType: parser.$valueType,
298
283
  $stateType: parser.$stateType,
299
284
  priority: parser.priority,
300
285
  [inheritParentAnnotationsKey]: true,
301
- [optionalStyleWrapperKey]: true,
302
286
  usage: parser.usage.length === 1 && parser.usage[0].type === "optional" ? parser.usage : [{
303
287
  type: "optional",
304
288
  terms: parser.usage
@@ -309,8 +293,9 @@ function prompt(parser, config) {
309
293
  const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
310
294
  return getDelegatingSuggestRuntimeNodes(parser, promptedParser, state, path, innerState, "prepend");
311
295
  },
312
- get initialState() {
313
- return new PromptBindInitialStateClass();
296
+ initialState: {
297
+ [promptBindStateKey]: true,
298
+ hasCliValue: false
314
299
  },
315
300
  parse: (context) => {
316
301
  const annotations = getAnnotations(context.state);
@@ -371,75 +356,66 @@ function prompt(parser, config) {
371
356
  if (r instanceof Promise) return r;
372
357
  return Promise.resolve(r);
373
358
  }
374
- if (state instanceof PromptBindInitialStateClass) {
375
- if (promptCache.has(state)) {
376
- const cached = promptCache.get(state);
377
- promptCache.delete(state);
378
- return cached;
359
+ const isProbe = exec?.phase === "parse";
360
+ const annotations = getAnnotations(state);
361
+ const innerInitialState = parser.initialState;
362
+ const effectiveInitialState = annotations != null && innerInitialState == null ? injectAnnotations(innerInitialState, annotations) : innerInitialState;
363
+ const finalizePrompt = () => {
364
+ if (shouldDeferPrompt(parser, state, exec)) {
365
+ let ph;
366
+ try {
367
+ ph = "placeholder" in parser ? parser.placeholder : void 0;
368
+ } catch {}
369
+ return Promise.resolve(deferredPromptResult(ph));
379
370
  }
380
- const hasDeferHook = typeof parser.shouldDeferCompletion === "function";
381
- const annotations = getAnnotations(state);
382
- const innerInitialState = parser.initialState;
383
- const effectiveInitialState = annotations != null && innerInitialState == null ? injectAnnotations(innerInitialState, annotations) : innerInitialState;
384
- if (hasDeferHook) {
385
- const annotatedR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
386
- const usePromptOrDeferSentinel = (res) => {
387
- if (res.success && res.value === void 0) return usePromptOrDefer(state, {
388
- success: false,
389
- error: []
390
- }, exec);
391
- return usePromptOrDefer(state, res, exec);
392
- };
393
- const cachedResult$1 = annotatedR instanceof Promise ? annotatedR.then(usePromptOrDeferSentinel) : usePromptOrDeferSentinel(annotatedR);
394
- promptCache.set(state, cachedResult$1);
395
- return cachedResult$1;
371
+ if (isProbe) {
372
+ let ph;
373
+ try {
374
+ ph = "placeholder" in parser ? parser.placeholder : void 0;
375
+ } catch {}
376
+ return Promise.resolve({
377
+ success: true,
378
+ value: ph
379
+ });
396
380
  }
381
+ return executePrompt();
382
+ };
383
+ const hasDeferHook = typeof parser.shouldDeferCompletion === "function";
384
+ const decideFromParse = (parseResult) => {
385
+ const consumed = parseResult.success ? parseResult.consumed.length : 0;
386
+ const cliState = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
387
+ const cliStateIsInjected = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationWrapper(cliState) !== cliState;
388
+ const isSourceBinding = shouldCompleteFromSourceBinding(cliState, state);
389
+ if (!isSourceBinding) return finalizePrompt();
390
+ const completeState = parseResult.success ? parseResult.next.state : effectiveInitialState;
391
+ const innerR = parser.complete(completeState, exec);
392
+ const handleCompleteResult = (res) => {
393
+ if (res.success && res.value === void 0 && cliStateIsInjected) return finalizePrompt();
394
+ if (!res.success) return finalizePrompt();
395
+ return Promise.resolve(res);
396
+ };
397
+ if (innerR instanceof Promise) return innerR.then(handleCompleteResult);
398
+ return handleCompleteResult(innerR);
399
+ };
400
+ return hasDeferHook ? (() => {
401
+ const innerR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
402
+ const handleDeferHookResult = (res) => {
403
+ if (res.success && res.value === void 0) return finalizePrompt();
404
+ if (!res.success) return finalizePrompt();
405
+ return Promise.resolve(res);
406
+ };
407
+ if (innerR instanceof Promise) return innerR.then(handleDeferHookResult);
408
+ return handleDeferHookResult(innerR);
409
+ })() : (() => {
397
410
  const simParseR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedState) => parser.parse({
398
411
  buffer: [],
399
412
  state: annotatedState,
400
413
  optionsTerminated: false,
401
414
  usage: parser.usage
402
415
  }));
403
- const decideFromParse = (parseResult) => {
404
- const consumed = parseResult.success ? parseResult.consumed.length : 0;
405
- const cliState$1 = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
406
- const isSourceBinding = shouldCompleteFromSourceBinding(cliState$1, state);
407
- if (isSourceBinding) {
408
- const cliStateIsInjected = cliState$1 != null && typeof cliState$1 === "object" && unwrapInjectedAnnotationWrapper(cliState$1) !== cliState$1;
409
- const handleCompleteResult = (res) => {
410
- if (res.success && res.value === void 0 && cliStateIsInjected) return executePrompt();
411
- return usePromptOrDefer(state, res, exec);
412
- };
413
- const completeState = parseResult.success ? parseResult.next.state : effectiveInitialState;
414
- const completeR = parser.complete(completeState, exec);
415
- if (completeR instanceof Promise) return completeR.then(handleCompleteResult);
416
- return handleCompleteResult(completeR);
417
- }
418
- return executePrompt();
419
- };
420
- const cachedResult = simParseR instanceof Promise ? simParseR.then(decideFromParse) : decideFromParse(simParseR);
421
- promptCache.set(state, cachedResult);
422
- return cachedResult;
423
- }
424
- const cliState = isPromptBindState(state) ? state.cliState : void 0;
425
- const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationWrapper(cliState) !== cliState;
426
- if (shouldCompleteFromSourceBinding(cliState, state)) {
427
- const useCompleteResultOrPrompt = (result) => {
428
- if (result.success && result.value === void 0 && cliStateIsInjectedAnnotationWrapper) return executePrompt();
429
- return usePromptOrDefer(state, result, exec);
430
- };
431
- const r = withAnnotatedInnerState(state, cliState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
432
- if (r instanceof Promise) return r.then(useCompleteResultOrPrompt);
433
- return useCompleteResultOrPrompt(r);
434
- }
435
- if (shouldDeferPrompt(parser, state, exec)) {
436
- let ph;
437
- try {
438
- ph = "placeholder" in parser ? parser.placeholder : void 0;
439
- } catch {}
440
- return Promise.resolve(deferredPromptResult(ph));
441
- }
442
- return executePrompt();
416
+ if (simParseR instanceof Promise) return simParseR.then(decideFromParse);
417
+ return decideFromParse(simParseR);
418
+ })();
443
419
  },
444
420
  suggest: (context, prefix) => {
445
421
  const innerState = isPromptBindState(context.state) ? context.state.cliState === void 0 ? parser.initialState : context.state.cliState : context.state;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/inquirer",
3
- "version": "1.0.0-dev.1734+46c419e1",
3
+ "version": "1.0.0-dev.1737+f1436575",
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.1734+46c419e1"
59
+ "@optique/core": "1.0.0-dev.1737+f1436575"
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.1734+46c419e1"
65
+ "@optique/env": "1.0.0-dev.1737+f1436575"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsdown",