@optique/inquirer 1.0.0-dev.1901 → 1.0.0-dev.1970

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/README.md CHANGED
@@ -9,7 +9,7 @@ when no CLI value is provided. The fallback priority is:
9
9
  CLI arguments > interactive prompt.
10
10
 
11
11
  Because interactive prompts are inherently asynchronous, the returned parser
12
- always has `$mode: "async"`.
12
+ always has `mode: "async"`.
13
13
 
14
14
  [Optique]: https://optique.dev/
15
15
  [Inquirer.js]: https://github.com/SBoudrias/Inquirer.js
package/dist/index.cjs CHANGED
@@ -23,7 +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
+ const __optique_core_extension = __toESM(require("@optique/core/extension"));
27
27
  const __optique_core_message = __toESM(require("@optique/core/message"));
28
28
 
29
29
  //#region src/index.ts
@@ -92,25 +92,12 @@ function deferredPromptResult(placeholderValue) {
92
92
  deferredKeys: keys
93
93
  };
94
94
  }
95
- function withAnnotationView(state, annotations, run) {
96
- const annotatedState = new Proxy(state, {
97
- get(target, key) {
98
- if (key === __optique_core_annotations.annotationKey) return annotations;
99
- const value = Reflect.get(target, key, target);
100
- return typeof value === "function" ? value.bind(target) : value;
101
- },
102
- has(target, key) {
103
- return key === __optique_core_annotations.annotationKey || Reflect.has(target, key);
104
- }
105
- });
106
- return run(annotatedState);
107
- }
108
95
  function withAnnotatedInnerState(sourceState, innerState, run) {
109
96
  const annotations = (0, __optique_core_annotations.getAnnotations)(sourceState);
110
- if (annotations == null || innerState == null || typeof innerState !== "object" || typeof innerState === "object" && __optique_core_annotations.annotationKey in innerState) return run(innerState);
111
- const inheritedState = (0, __optique_core_annotations.inheritAnnotations)(sourceState, innerState);
97
+ if (annotations == null || innerState == null || typeof innerState !== "object" || (0, __optique_core_annotations.getAnnotations)(innerState) != null) return run(innerState);
98
+ const inheritedState = (0, __optique_core_extension.inheritAnnotations)(sourceState, innerState);
112
99
  if (inheritedState !== innerState) return run(inheritedState);
113
- return withAnnotationView(innerState, annotations, (annotatedState) => run(annotatedState));
100
+ return run((0, __optique_core_extension.withAnnotationView)(innerState, annotations));
114
101
  }
115
102
  /**
116
103
  * Wraps a parser with an interactive Inquirer.js prompt fallback.
@@ -119,7 +106,7 @@ function withAnnotatedInnerState(sourceState, innerState, run) {
119
106
  * that value is used directly. When no CLI value is found, an interactive
120
107
  * prompt is shown to the user.
121
108
  *
122
- * The returned parser always has `$mode: "async"` because Inquirer.js prompts
109
+ * The returned parser always has `mode: "async"` because Inquirer.js prompts
123
110
  * are inherently asynchronous.
124
111
  *
125
112
  * Example:
@@ -150,7 +137,7 @@ function prompt(parser, config) {
150
137
  const cfg = config;
151
138
  function shouldAttemptInnerCompletion(cliState, state) {
152
139
  if (cliState == null) return false;
153
- const cliStateHasAnnotations = typeof cliState === "object" && __optique_core_annotations.annotationKey in cliState;
140
+ const cliStateHasAnnotations = (0, __optique_core_annotations.getAnnotations)(cliState) != null;
154
141
  if (cliStateHasAnnotations) return true;
155
142
  if ((0, __optique_core_annotations.getAnnotations)(state) == null || typeof cliState !== "object") return false;
156
143
  if ("hasCliValue" in cliState) return true;
@@ -162,9 +149,9 @@ function prompt(parser, config) {
162
149
  return state != null && typeof state === "object" && "hasCliValue" in state && Object.getOwnPropertySymbols(state).length > 0;
163
150
  }
164
151
  function shouldCompleteFromSourceBinding(cliState, state) {
165
- const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState) !== cliState;
166
- const requiresSourceBindingForAnnotationWrapper = Reflect.get(parser, __optique_core_parser.annotationWrapperRequiresSourceBindingKey) === true;
167
- 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]);
152
+ const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && (0, __optique_core_extension.unwrapInjectedAnnotationState)(cliState) !== cliState;
153
+ const requiresSourceBindingForAnnotationWrapper = (0, __optique_core_extension.getTraits)(parser).requiresSourceBinding === true;
154
+ const hasNestedSourceBinding = hasSourceBindingMarker(cliState) || Array.isArray(cliState) && cliState.length === 1 && (hasSourceBindingMarker(cliState[0]) || cliState[0] != null && typeof cliState[0] === "object" && (0, __optique_core_annotations.getAnnotations)(cliState[0]) != null);
168
155
  if (cliStateIsInjectedAnnotationWrapper && requiresSourceBindingForAnnotationWrapper) return hasNestedSourceBinding;
169
156
  return shouldAttemptInnerCompletion(cliState, state) || hasNestedSourceBinding;
170
157
  }
@@ -301,11 +288,10 @@ function prompt(parser, config) {
301
288
  return validatePromptedValue(result);
302
289
  }
303
290
  const promptedParser = {
304
- $mode: "async",
291
+ mode: "async",
305
292
  $valueType: parser.$valueType,
306
293
  $stateType: parser.$stateType,
307
294
  priority: parser.priority,
308
- [__optique_core_parser.inheritParentAnnotationsKey]: true,
309
295
  usage: parser.usage.length === 1 && parser.usage[0].type === "optional" ? parser.usage : [{
310
296
  type: "optional",
311
297
  terms: parser.usage
@@ -314,7 +300,7 @@ function prompt(parser, config) {
314
300
  acceptingAnyToken: parser.acceptingAnyToken,
315
301
  getSuggestRuntimeNodes(state, path) {
316
302
  const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
317
- return (0, __optique_core_parser.getDelegatingSuggestRuntimeNodes)(parser, promptedParser, state, path, innerState, "prepend");
303
+ return (0, __optique_core_extension.delegateSuggestNodes)(parser, promptedParser, state, path, innerState, "prepend");
318
304
  },
319
305
  initialState: {
320
306
  [promptBindStateKey]: true,
@@ -327,17 +313,16 @@ function prompt(parser, config) {
327
313
  ...context,
328
314
  state: innerState
329
315
  } : context;
330
- const effectiveInnerState = annotations != null && innerState == null && Reflect.get(parser, __optique_core_parser.inheritParentAnnotationsKey) === true ? (0, __optique_core_annotations.injectAnnotations)(innerState, annotations) : innerState;
316
+ const effectiveInnerState = annotations != null && innerState == null && (0, __optique_core_extension.getTraits)(parser).inheritsAnnotations === true ? (0, __optique_core_extension.injectAnnotations)(innerState, annotations) : innerState;
331
317
  const processResult = (result$1) => {
332
318
  if (result$1.success) {
333
- 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;
319
+ 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_extension.injectAnnotations)(result$1.next.state, annotations) : result$1.next.state;
334
320
  const cliConsumed = result$1.consumed.length > 0;
335
- const nextState$1 = {
321
+ const nextState$1 = (0, __optique_core_extension.injectAnnotations)({
336
322
  [promptBindStateKey]: true,
337
323
  hasCliValue: cliConsumed,
338
- cliState,
339
- ...annotations != null ? { [__optique_core_annotations.annotationKey]: annotations } : {}
340
- };
324
+ cliState
325
+ }, annotations);
341
326
  return {
342
327
  success: true,
343
328
  ...result$1.provisional ? { provisional: true } : {},
@@ -349,11 +334,10 @@ function prompt(parser, config) {
349
334
  };
350
335
  }
351
336
  if (result$1.consumed > 0) return result$1;
352
- const nextState = {
337
+ const nextState = (0, __optique_core_extension.injectAnnotations)({
353
338
  [promptBindStateKey]: true,
354
- hasCliValue: false,
355
- ...annotations != null ? { [__optique_core_annotations.annotationKey]: annotations } : {}
356
- };
339
+ hasCliValue: false
340
+ }, annotations);
357
341
  return {
358
342
  success: true,
359
343
  next: {
@@ -383,7 +367,7 @@ function prompt(parser, config) {
383
367
  const annotations = (0, __optique_core_annotations.getAnnotations)(state);
384
368
  const innerInitialState = parser.initialState;
385
369
  const shouldInheritInitialStateAnnotations = annotations != null && (innerInitialState == null || typeof innerInitialState === "object");
386
- const effectiveInitialState = shouldInheritInitialStateAnnotations ? (0, __optique_core_annotations.inheritAnnotations)(state, innerInitialState) : innerInitialState;
370
+ const effectiveInitialState = shouldInheritInitialStateAnnotations ? (0, __optique_core_extension.inheritAnnotations)(state, innerInitialState) : innerInitialState;
387
371
  const readPlaceholder = () => {
388
372
  try {
389
373
  return "placeholder" in parser ? parser.placeholder : void 0;
@@ -404,7 +388,7 @@ function prompt(parser, config) {
404
388
  const decideFromParse = (parseResult) => {
405
389
  const consumed = parseResult.success ? parseResult.consumed.length : 0;
406
390
  const cliState = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
407
- const cliStateIsInjected = cliState != null && typeof cliState === "object" && (0, __optique_core_annotations.unwrapInjectedAnnotationWrapper)(cliState) !== cliState;
391
+ const cliStateIsInjected = cliState != null && typeof cliState === "object" && (0, __optique_core_extension.unwrapInjectedAnnotationState)(cliState) !== cliState;
408
392
  const isSourceBinding = shouldCompleteFromSourceBinding(cliState, state);
409
393
  if (!isSourceBinding) return finalizePrompt();
410
394
  const completeState = parseResult.success ? parseResult.next.state : effectiveInitialState;
@@ -453,7 +437,7 @@ function prompt(parser, config) {
453
437
  return parser.getDocFragments(state, defaultValue);
454
438
  }
455
439
  };
456
- (0, __optique_core_parser.defineInheritedAnnotationParser)(promptedParser);
440
+ (0, __optique_core_extension.defineTraits)(promptedParser, { inheritsAnnotations: true });
457
441
  if ("placeholder" in parser) Object.defineProperty(promptedParser, "placeholder", {
458
442
  get() {
459
443
  try {
@@ -470,7 +454,7 @@ function prompt(parser, config) {
470
454
  configurable: true,
471
455
  enumerable: false
472
456
  });
473
- const dependencyMetadata = (0, __optique_core_parser.composeWrappedSourceMetadata)(parser.dependencyMetadata, (source) => ({
457
+ const dependencyMetadata = (0, __optique_core_extension.mapSourceMetadata)(parser, (source) => ({
474
458
  ...source,
475
459
  extractSourceValue: (state) => {
476
460
  if (!isPromptBindState(state)) return source.extractSourceValue(state);
package/dist/index.d.cts CHANGED
@@ -328,7 +328,7 @@ type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number
328
328
  * that value is used directly. When no CLI value is found, an interactive
329
329
  * prompt is shown to the user.
330
330
  *
331
- * The returned parser always has `$mode: "async"` because Inquirer.js prompts
331
+ * The returned parser always has `mode: "async"` because Inquirer.js prompts
332
332
  * are inherently asynchronous.
333
333
  *
334
334
  * Example:
package/dist/index.d.ts CHANGED
@@ -328,7 +328,7 @@ type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number
328
328
  * that value is used directly. When no CLI value is found, an interactive
329
329
  * prompt is shown to the user.
330
330
  *
331
- * The returned parser always has `$mode: "async"` because Inquirer.js prompts
331
+ * The returned parser always has `mode: "async"` because Inquirer.js prompts
332
332
  * are inherently asynchronous.
333
333
  *
334
334
  * Example:
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Separator, checkbox, confirm, editor, expand, input, number, password, rawlist, select } from "@inquirer/prompts";
2
- import { annotationKey, getAnnotations, inheritAnnotations, injectAnnotations, unwrapInjectedAnnotationWrapper } from "@optique/core/annotations";
3
- import { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, defineInheritedAnnotationParser, getDelegatingSuggestRuntimeNodes, inheritParentAnnotationsKey } from "@optique/core/parser";
2
+ import { getAnnotations } from "@optique/core/annotations";
3
+ import { defineTraits, delegateSuggestNodes, getTraits, inheritAnnotations, injectAnnotations, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView } from "@optique/core/extension";
4
4
  import { message } from "@optique/core/message";
5
5
 
6
6
  //#region src/index.ts
@@ -69,25 +69,12 @@ function deferredPromptResult(placeholderValue) {
69
69
  deferredKeys: keys
70
70
  };
71
71
  }
72
- function withAnnotationView(state, annotations, run) {
73
- const annotatedState = new Proxy(state, {
74
- get(target, key) {
75
- if (key === annotationKey) return annotations;
76
- const value = Reflect.get(target, key, target);
77
- return typeof value === "function" ? value.bind(target) : value;
78
- },
79
- has(target, key) {
80
- return key === annotationKey || Reflect.has(target, key);
81
- }
82
- });
83
- return run(annotatedState);
84
- }
85
72
  function withAnnotatedInnerState(sourceState, innerState, run) {
86
73
  const annotations = getAnnotations(sourceState);
87
- if (annotations == null || innerState == null || typeof innerState !== "object" || typeof innerState === "object" && annotationKey in innerState) return run(innerState);
74
+ if (annotations == null || innerState == null || typeof innerState !== "object" || getAnnotations(innerState) != null) return run(innerState);
88
75
  const inheritedState = inheritAnnotations(sourceState, innerState);
89
76
  if (inheritedState !== innerState) return run(inheritedState);
90
- return withAnnotationView(innerState, annotations, (annotatedState) => run(annotatedState));
77
+ return run(withAnnotationView(innerState, annotations));
91
78
  }
92
79
  /**
93
80
  * Wraps a parser with an interactive Inquirer.js prompt fallback.
@@ -96,7 +83,7 @@ function withAnnotatedInnerState(sourceState, innerState, run) {
96
83
  * that value is used directly. When no CLI value is found, an interactive
97
84
  * prompt is shown to the user.
98
85
  *
99
- * The returned parser always has `$mode: "async"` because Inquirer.js prompts
86
+ * The returned parser always has `mode: "async"` because Inquirer.js prompts
100
87
  * are inherently asynchronous.
101
88
  *
102
89
  * Example:
@@ -127,7 +114,7 @@ function prompt(parser, config) {
127
114
  const cfg = config;
128
115
  function shouldAttemptInnerCompletion(cliState, state) {
129
116
  if (cliState == null) return false;
130
- const cliStateHasAnnotations = typeof cliState === "object" && annotationKey in cliState;
117
+ const cliStateHasAnnotations = getAnnotations(cliState) != null;
131
118
  if (cliStateHasAnnotations) return true;
132
119
  if (getAnnotations(state) == null || typeof cliState !== "object") return false;
133
120
  if ("hasCliValue" in cliState) return true;
@@ -139,9 +126,9 @@ function prompt(parser, config) {
139
126
  return state != null && typeof state === "object" && "hasCliValue" in state && Object.getOwnPropertySymbols(state).length > 0;
140
127
  }
141
128
  function shouldCompleteFromSourceBinding(cliState, state) {
142
- const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationWrapper(cliState) !== cliState;
143
- const requiresSourceBindingForAnnotationWrapper = Reflect.get(parser, annotationWrapperRequiresSourceBindingKey) === true;
144
- const hasNestedSourceBinding = hasSourceBindingMarker(cliState) || Array.isArray(cliState) && cliState.length === 1 && (hasSourceBindingMarker(cliState[0]) || cliState[0] != null && typeof cliState[0] === "object" && annotationKey in cliState[0]);
129
+ const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationState(cliState) !== cliState;
130
+ const requiresSourceBindingForAnnotationWrapper = getTraits(parser).requiresSourceBinding === true;
131
+ const hasNestedSourceBinding = hasSourceBindingMarker(cliState) || Array.isArray(cliState) && cliState.length === 1 && (hasSourceBindingMarker(cliState[0]) || cliState[0] != null && typeof cliState[0] === "object" && getAnnotations(cliState[0]) != null);
145
132
  if (cliStateIsInjectedAnnotationWrapper && requiresSourceBindingForAnnotationWrapper) return hasNestedSourceBinding;
146
133
  return shouldAttemptInnerCompletion(cliState, state) || hasNestedSourceBinding;
147
134
  }
@@ -278,11 +265,10 @@ function prompt(parser, config) {
278
265
  return validatePromptedValue(result);
279
266
  }
280
267
  const promptedParser = {
281
- $mode: "async",
268
+ mode: "async",
282
269
  $valueType: parser.$valueType,
283
270
  $stateType: parser.$stateType,
284
271
  priority: parser.priority,
285
- [inheritParentAnnotationsKey]: true,
286
272
  usage: parser.usage.length === 1 && parser.usage[0].type === "optional" ? parser.usage : [{
287
273
  type: "optional",
288
274
  terms: parser.usage
@@ -291,7 +277,7 @@ function prompt(parser, config) {
291
277
  acceptingAnyToken: parser.acceptingAnyToken,
292
278
  getSuggestRuntimeNodes(state, path) {
293
279
  const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
294
- return getDelegatingSuggestRuntimeNodes(parser, promptedParser, state, path, innerState, "prepend");
280
+ return delegateSuggestNodes(parser, promptedParser, state, path, innerState, "prepend");
295
281
  },
296
282
  initialState: {
297
283
  [promptBindStateKey]: true,
@@ -304,17 +290,16 @@ function prompt(parser, config) {
304
290
  ...context,
305
291
  state: innerState
306
292
  } : context;
307
- const effectiveInnerState = annotations != null && innerState == null && Reflect.get(parser, inheritParentAnnotationsKey) === true ? injectAnnotations(innerState, annotations) : innerState;
293
+ const effectiveInnerState = annotations != null && innerState == null && getTraits(parser).inheritsAnnotations === true ? injectAnnotations(innerState, annotations) : innerState;
308
294
  const processResult = (result$1) => {
309
295
  if (result$1.success) {
310
296
  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;
311
297
  const cliConsumed = result$1.consumed.length > 0;
312
- const nextState$1 = {
298
+ const nextState$1 = injectAnnotations({
313
299
  [promptBindStateKey]: true,
314
300
  hasCliValue: cliConsumed,
315
- cliState,
316
- ...annotations != null ? { [annotationKey]: annotations } : {}
317
- };
301
+ cliState
302
+ }, annotations);
318
303
  return {
319
304
  success: true,
320
305
  ...result$1.provisional ? { provisional: true } : {},
@@ -326,11 +311,10 @@ function prompt(parser, config) {
326
311
  };
327
312
  }
328
313
  if (result$1.consumed > 0) return result$1;
329
- const nextState = {
314
+ const nextState = injectAnnotations({
330
315
  [promptBindStateKey]: true,
331
- hasCliValue: false,
332
- ...annotations != null ? { [annotationKey]: annotations } : {}
333
- };
316
+ hasCliValue: false
317
+ }, annotations);
334
318
  return {
335
319
  success: true,
336
320
  next: {
@@ -381,7 +365,7 @@ function prompt(parser, config) {
381
365
  const decideFromParse = (parseResult) => {
382
366
  const consumed = parseResult.success ? parseResult.consumed.length : 0;
383
367
  const cliState = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
384
- const cliStateIsInjected = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationWrapper(cliState) !== cliState;
368
+ const cliStateIsInjected = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationState(cliState) !== cliState;
385
369
  const isSourceBinding = shouldCompleteFromSourceBinding(cliState, state);
386
370
  if (!isSourceBinding) return finalizePrompt();
387
371
  const completeState = parseResult.success ? parseResult.next.state : effectiveInitialState;
@@ -430,7 +414,7 @@ function prompt(parser, config) {
430
414
  return parser.getDocFragments(state, defaultValue);
431
415
  }
432
416
  };
433
- defineInheritedAnnotationParser(promptedParser);
417
+ defineTraits(promptedParser, { inheritsAnnotations: true });
434
418
  if ("placeholder" in parser) Object.defineProperty(promptedParser, "placeholder", {
435
419
  get() {
436
420
  try {
@@ -447,7 +431,7 @@ function prompt(parser, config) {
447
431
  configurable: true,
448
432
  enumerable: false
449
433
  });
450
- const dependencyMetadata = composeWrappedSourceMetadata(parser.dependencyMetadata, (source) => ({
434
+ const dependencyMetadata = mapSourceMetadata(parser, (source) => ({
451
435
  ...source,
452
436
  extractSourceValue: (state) => {
453
437
  if (!isPromptBindState(state)) return source.extractSourceValue(state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/inquirer",
3
- "version": "1.0.0-dev.1901+a2ce4da0",
3
+ "version": "1.0.0-dev.1970+0182ae32",
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.1901+a2ce4da0"
59
+ "@optique/core": "1.0.0-dev.1970+0182ae32"
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.1901+a2ce4da0"
65
+ "@optique/env": "1.0.0-dev.1970+0182ae32"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsdown",