@optique/core 1.2.0-dev.2229 → 1.2.0-dev.2232

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
@@ -34,6 +34,7 @@ exports.createParserContext = require_internal_parser.createParserContext;
34
34
  exports.cron = require_valueparser.cron;
35
35
  exports.deduplicateDocEntries = require_doc.deduplicateDocEntries;
36
36
  exports.deduplicateDocFragments = require_doc.deduplicateDocFragments;
37
+ exports.deferredValue = require_modifiers.deferredValue;
37
38
  exports.dependency = require_internal_dependency.dependency;
38
39
  exports.deriveFrom = require_internal_dependency.deriveFrom;
39
40
  exports.deriveFromAsync = require_internal_dependency.deriveFromAsync;
@@ -67,6 +68,7 @@ exports.integer = require_valueparser.integer;
67
68
  exports.ip = require_valueparser.ip;
68
69
  exports.ipv4 = require_valueparser.ipv4;
69
70
  exports.ipv6 = require_valueparser.ipv6;
71
+ exports.isDeferredValue = require_modifiers.isDeferredValue;
70
72
  exports.isDependencySource = require_internal_dependency.isDependencySource;
71
73
  exports.isDerivedValueParser = require_internal_dependency.isDerivedValueParser;
72
74
  exports.isDocEntryHidden = require_doc.isDocEntryHidden;
package/dist/index.d.cts CHANGED
@@ -6,10 +6,10 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
6
6
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid } from "./valueparser.cjs";
7
7
  import { CombineModes, DocState, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, Parser, ParserContext, ParserResult, Result, Suggestion, createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./internal/parser.cjs";
8
8
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
9
- import { FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, fluent, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
9
+ import { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, deferredValue, fluent, isDeferredValue, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
10
10
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, SeqOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, seq, tuple } from "./constructs.cjs";
11
11
  import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.cjs";
12
12
  import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, isDependencySource, isDerivedValueParser } from "./internal/dependency.cjs";
13
13
  import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
14
14
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.cjs";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, deferredValue, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredValue, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/index.d.ts CHANGED
@@ -6,10 +6,10 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
6
6
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid } from "./valueparser.js";
7
7
  import { CombineModes, DocState, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, Parser, ParserContext, ParserResult, Result, Suggestion, createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./internal/parser.js";
8
8
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
9
- import { FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, fluent, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
9
+ import { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, deferredValue, fluent, isDeferredValue, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
10
10
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, SeqOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, seq, tuple } from "./constructs.js";
11
11
  import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.js";
12
12
  import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, isDependencySource, isDerivedValueParser } from "./internal/dependency.js";
13
13
  import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
14
14
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.js";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, deferredValue, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredValue, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/index.js CHANGED
@@ -5,11 +5,11 @@ import { cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDo
5
5
  import { dependency, deriveFrom, deriveFromAsync, deriveFromSync, isDependencySource, isDerivedValueParser } from "./internal/dependency.js";
6
6
  import { createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./internal/parser.js";
7
7
  import { bash, fish, nu, pwsh, zsh } from "./completion.js";
8
- import { WithDefaultError, fluent, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
8
+ import { WithDefaultError, deferredValue, fluent, isDeferredValue, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
9
9
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, seq, tuple } from "./constructs.js";
10
10
  import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
11
11
  import { checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid } from "./valueparser.js";
12
12
  import { argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.js";
13
13
  import { RunParserError, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
14
14
 
15
- export { DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
15
+ export { DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, deferredValue, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredValue, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
@@ -845,6 +845,93 @@ function map(parser, transform) {
845
845
  }
846
846
  return fluent(mappedParser);
847
847
  }
848
+ const deferredValueBrand = Symbol.for("@optique/core/deferredValue");
849
+ /**
850
+ * Brands a value-producing function as a {@link DeferredValue}.
851
+ *
852
+ * The brand is a hidden, non-enumerable symbol so {@link isDeferredValue} can
853
+ * recognize the value while object inspection only sees `source`. The `source`
854
+ * property is enumerable but readonly and non-configurable.
855
+ *
856
+ * @param call The value-producing function.
857
+ * @param source The branch that produced the value.
858
+ * @returns The same function decorated as a {@link DeferredValue}.
859
+ */
860
+ function brandDeferredValue(call, source) {
861
+ Object.defineProperties(call, {
862
+ [deferredValueBrand]: {
863
+ value: true,
864
+ enumerable: false,
865
+ writable: false,
866
+ configurable: false
867
+ },
868
+ source: {
869
+ value: source,
870
+ enumerable: true,
871
+ writable: false,
872
+ configurable: false
873
+ }
874
+ });
875
+ return call;
876
+ }
877
+ /**
878
+ * Builds the `"specified"` branch: a function that returns the parsed value
879
+ * and ignores any handler-time context.
880
+ */
881
+ function makeSpecifiedDeferredValue(value) {
882
+ return brandDeferredValue((_ctx) => value, "specified");
883
+ }
884
+ /**
885
+ * Builds the `"fallback"` branch: a function that runs the fallback resolver,
886
+ * optionally memoizing the resolved value or in-flight promise.
887
+ */
888
+ function makeFallbackDeferredValue(fallback, memoize) {
889
+ if (!memoize) return brandDeferredValue((ctx) => fallback(ctx), "fallback");
890
+ let settled = false;
891
+ let settledValue;
892
+ let inFlight;
893
+ const call = (ctx) => {
894
+ if (settled) return settledValue;
895
+ if (inFlight != null) return inFlight;
896
+ const result = fallback(ctx);
897
+ if (!isPromiseLike(result)) {
898
+ settled = true;
899
+ settledValue = result;
900
+ return result;
901
+ }
902
+ const promise = Promise.resolve(result).then((resolved) => {
903
+ settled = true;
904
+ settledValue = resolved;
905
+ inFlight = void 0;
906
+ return resolved;
907
+ }, (error) => {
908
+ inFlight = void 0;
909
+ throw error;
910
+ });
911
+ inFlight = promise;
912
+ return promise;
913
+ };
914
+ return brandDeferredValue(call, "fallback");
915
+ }
916
+ function deferredValue(parser, fallback, options) {
917
+ const memoize = options?.memoize ?? false;
918
+ return map(optional(map(parser, (value) => ({ value }))), (matched) => matched === void 0 ? makeFallbackDeferredValue(fallback, memoize) : makeSpecifiedDeferredValue(matched.value));
919
+ }
920
+ /**
921
+ * Checks whether a value is a {@link DeferredValue} produced by
922
+ * {@link deferredValue}.
923
+ *
924
+ * Useful for tests, generic result walkers, and debugging code that only has an
925
+ * `unknown` value. In ordinary code the static type already indicates whether a
926
+ * field is a {@link DeferredValue}.
927
+ *
928
+ * @param value The value to check.
929
+ * @returns `true` if `value` is a {@link DeferredValue}.
930
+ * @since 1.2.0
931
+ */
932
+ function isDeferredValue(value) {
933
+ return typeof value === "function" && value[deferredValueBrand] === true;
934
+ }
848
935
  /**
849
936
  * Creates a parser that allows multiple occurrences of a given parser.
850
937
  * This parser can be used to parse multiple values of the same type,
@@ -1643,6 +1730,13 @@ function fluent(parser) {
1643
1730
  },
1644
1731
  configurable: true,
1645
1732
  enumerable: false
1733
+ },
1734
+ deferredValue: {
1735
+ value(fallback, options) {
1736
+ return deferredValue(parser, fallback, options);
1737
+ },
1738
+ configurable: true,
1739
+ enumerable: false
1646
1740
  }
1647
1741
  });
1648
1742
  return fluentParser;
@@ -1650,7 +1744,9 @@ function fluent(parser) {
1650
1744
 
1651
1745
  //#endregion
1652
1746
  exports.WithDefaultError = WithDefaultError;
1747
+ exports.deferredValue = deferredValue;
1653
1748
  exports.fluent = fluent;
1749
+ exports.isDeferredValue = isDeferredValue;
1654
1750
  exports.map = map;
1655
1751
  exports.multiple = multiple;
1656
1752
  exports.nonEmpty = nonEmpty;
@@ -180,6 +180,110 @@ declare function withDefault<M extends Mode, TValue, TState, const TDefault = TV
180
180
  * ```
181
181
  */
182
182
  declare function map<M extends Mode, T, U, TState>(parser: Parser<M, T, TState>, transform: (value: T) => U): FluentParser<M, U, TState>;
183
+ /**
184
+ * Identifies which branch a {@link DeferredValue} resolved from.
185
+ *
186
+ * - `"specified"` means the wrapped parser produced a value, whether from
187
+ * CLI input or another source such as `bindEnv()`/`bindConfig()`.
188
+ * - `"fallback"` means {@link deferredValue} selected the fallback resolver.
189
+ *
190
+ * @since 1.2.0
191
+ */
192
+ type DeferredValueSource = "specified" | "fallback";
193
+ /**
194
+ * A handler-time value produced by {@link deferredValue}.
195
+ *
196
+ * It is a value-producing function rather than a scalar value. When the
197
+ * wrapped parser produced a value, calling it returns that value. Otherwise
198
+ * calling it runs the fallback resolver. The {@link DeferredValue.source}
199
+ * property tells which branch was selected without invoking the function.
200
+ *
201
+ * The call signature returns `T | Promise<T>` regardless of the wrapped
202
+ * parser's mode, so a synchronous parser may still pair with an asynchronous
203
+ * fallback resolver.
204
+ *
205
+ * @template T The resolved value type.
206
+ * @template C The handler-time context type passed to the fallback resolver.
207
+ * @since 1.2.0
208
+ */
209
+ type DeferredValue<T, C = void> = ([C] extends [void] ? (() => T | Promise<T>) : [undefined] extends [C] ? ((ctx?: C) => T | Promise<T>) : ((ctx: C) => T | Promise<T>)) & {
210
+ /**
211
+ * Which branch produced this value: `"specified"` when the wrapped parser
212
+ * produced a value, `"fallback"` when the fallback resolver was selected.
213
+ */
214
+ readonly source: DeferredValueSource;
215
+ };
216
+ /**
217
+ * Options for {@link deferredValue}.
218
+ * @since 1.2.0
219
+ */
220
+ interface DeferredValueOptions {
221
+ /**
222
+ * When `true`, a fallback-backed {@link DeferredValue} caches its first
223
+ * resolved value (or in-flight promise) and reuses it on later calls.
224
+ * A rejected fallback is not cached, so the next call retries it. Defaults
225
+ * to `false`, meaning every call re-runs the fallback resolver.
226
+ */
227
+ readonly memoize?: boolean;
228
+ }
229
+ /**
230
+ * Wraps a parser so its value is resolved by the command handler instead of
231
+ * during parsing.
232
+ *
233
+ * The parsed field becomes a {@link DeferredValue}: a value-producing function.
234
+ * When the wrapped parser produced a value, calling the function returns that
235
+ * value and {@link DeferredValue.source} is `"specified"`. When the wrapped
236
+ * parser did not produce a value, calling the function runs `fallback` and
237
+ * `source` is `"fallback"`. The fallback runs at handler time, so its errors
238
+ * are handler errors rather than parser errors. A value that is specified but
239
+ * invalid still fails during parsing.
240
+ *
241
+ * Like {@link optional}, the wrapped parser keeps its place in usage and help;
242
+ * only the result type changes. The fallback context type `C` is inferred from
243
+ * the `fallback` parameter.
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * const parser = object({
248
+ * serviceName: option("--service-name", string()),
249
+ * apiToken: deferredValue(
250
+ * option("--api-token", string()),
251
+ * ({ serviceName }: { readonly serviceName: string }) =>
252
+ * promptForApiToken(serviceName),
253
+ * ),
254
+ * });
255
+ *
256
+ * const parsed = parse(parser, argv);
257
+ * // The prompt only runs if this branch is reached.
258
+ * const apiToken = await parsed.apiToken({
259
+ * serviceName: parsed.serviceName,
260
+ * });
261
+ * ```
262
+ *
263
+ * @template M The execution mode of the wrapped parser.
264
+ * @template T The resolved value type.
265
+ * @template S The state type of the wrapped parser.
266
+ * @param parser The parser that reads the CLI value.
267
+ * @param fallback A resolver run at handler time when no value was specified.
268
+ * @param options Optional {@link DeferredValueOptions}.
269
+ * @returns A parser whose value is a {@link DeferredValue}.
270
+ * @since 1.2.0
271
+ */
272
+ declare function deferredValue<M extends Mode, T, S>(parser: Parser<M, T, S>, fallback: () => T | Promise<T>, options?: DeferredValueOptions): FluentParser<M, DeferredValue<T>, [S] | undefined>;
273
+ declare function deferredValue<M extends Mode, T, S, C>(parser: Parser<M, T, S>, fallback: (ctx: C) => T | Promise<T>, options?: DeferredValueOptions): FluentParser<M, DeferredValue<T, C>, [S] | undefined>;
274
+ /**
275
+ * Checks whether a value is a {@link DeferredValue} produced by
276
+ * {@link deferredValue}.
277
+ *
278
+ * Useful for tests, generic result walkers, and debugging code that only has an
279
+ * `unknown` value. In ordinary code the static type already indicates whether a
280
+ * field is a {@link DeferredValue}.
281
+ *
282
+ * @param value The value to check.
283
+ * @returns `true` if `value` is a {@link DeferredValue}.
284
+ * @since 1.2.0
285
+ */
286
+ declare function isDeferredValue(value: unknown): value is DeferredValue<unknown>;
183
287
  /**
184
288
  * Options for the {@link multiple} parser.
185
289
  */
@@ -306,6 +410,15 @@ interface ParserModifiers<M extends Mode = "sync", TValue = unknown, TState = un
306
410
  * @returns A parser that produces this parser's value or the default value.
307
411
  */
308
412
  withDefault<const TDefault = TValue>(defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): FluentParser<M, TValue | TDefault, [TState] | undefined>;
413
+ /**
414
+ * Defers this parser's value so the command handler resolves it.
415
+ *
416
+ * @param fallback A resolver run at handler time when no value was specified.
417
+ * @param options Optional {@link DeferredValueOptions}.
418
+ * @returns A parser whose value is a {@link DeferredValue}.
419
+ */
420
+ deferredValue(fallback: () => TValue | Promise<TValue>, options?: DeferredValueOptions): FluentParser<M, DeferredValue<TValue>, [TState] | undefined>;
421
+ deferredValue<C>(fallback: (ctx: C) => TValue | Promise<TValue>, options?: DeferredValueOptions): FluentParser<M, DeferredValue<TValue, C>, [TState] | undefined>;
309
422
  /**
310
423
  * Allows this parser to match multiple times.
311
424
  *
@@ -343,4 +456,4 @@ type FluentParser<M extends Mode = "sync", TValue = unknown, TState = unknown> =
343
456
  */
344
457
  declare function fluent<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>): FluentParser<M, TValue, TState>;
345
458
  //#endregion
346
- export { FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, fluent, map, multiple, nonEmpty, optional, withDefault };
459
+ export { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, deferredValue, fluent, isDeferredValue, map, multiple, nonEmpty, optional, withDefault };
@@ -180,6 +180,110 @@ declare function withDefault<M extends Mode, TValue, TState, const TDefault = TV
180
180
  * ```
181
181
  */
182
182
  declare function map<M extends Mode, T, U, TState>(parser: Parser<M, T, TState>, transform: (value: T) => U): FluentParser<M, U, TState>;
183
+ /**
184
+ * Identifies which branch a {@link DeferredValue} resolved from.
185
+ *
186
+ * - `"specified"` means the wrapped parser produced a value, whether from
187
+ * CLI input or another source such as `bindEnv()`/`bindConfig()`.
188
+ * - `"fallback"` means {@link deferredValue} selected the fallback resolver.
189
+ *
190
+ * @since 1.2.0
191
+ */
192
+ type DeferredValueSource = "specified" | "fallback";
193
+ /**
194
+ * A handler-time value produced by {@link deferredValue}.
195
+ *
196
+ * It is a value-producing function rather than a scalar value. When the
197
+ * wrapped parser produced a value, calling it returns that value. Otherwise
198
+ * calling it runs the fallback resolver. The {@link DeferredValue.source}
199
+ * property tells which branch was selected without invoking the function.
200
+ *
201
+ * The call signature returns `T | Promise<T>` regardless of the wrapped
202
+ * parser's mode, so a synchronous parser may still pair with an asynchronous
203
+ * fallback resolver.
204
+ *
205
+ * @template T The resolved value type.
206
+ * @template C The handler-time context type passed to the fallback resolver.
207
+ * @since 1.2.0
208
+ */
209
+ type DeferredValue<T, C = void> = ([C] extends [void] ? (() => T | Promise<T>) : [undefined] extends [C] ? ((ctx?: C) => T | Promise<T>) : ((ctx: C) => T | Promise<T>)) & {
210
+ /**
211
+ * Which branch produced this value: `"specified"` when the wrapped parser
212
+ * produced a value, `"fallback"` when the fallback resolver was selected.
213
+ */
214
+ readonly source: DeferredValueSource;
215
+ };
216
+ /**
217
+ * Options for {@link deferredValue}.
218
+ * @since 1.2.0
219
+ */
220
+ interface DeferredValueOptions {
221
+ /**
222
+ * When `true`, a fallback-backed {@link DeferredValue} caches its first
223
+ * resolved value (or in-flight promise) and reuses it on later calls.
224
+ * A rejected fallback is not cached, so the next call retries it. Defaults
225
+ * to `false`, meaning every call re-runs the fallback resolver.
226
+ */
227
+ readonly memoize?: boolean;
228
+ }
229
+ /**
230
+ * Wraps a parser so its value is resolved by the command handler instead of
231
+ * during parsing.
232
+ *
233
+ * The parsed field becomes a {@link DeferredValue}: a value-producing function.
234
+ * When the wrapped parser produced a value, calling the function returns that
235
+ * value and {@link DeferredValue.source} is `"specified"`. When the wrapped
236
+ * parser did not produce a value, calling the function runs `fallback` and
237
+ * `source` is `"fallback"`. The fallback runs at handler time, so its errors
238
+ * are handler errors rather than parser errors. A value that is specified but
239
+ * invalid still fails during parsing.
240
+ *
241
+ * Like {@link optional}, the wrapped parser keeps its place in usage and help;
242
+ * only the result type changes. The fallback context type `C` is inferred from
243
+ * the `fallback` parameter.
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * const parser = object({
248
+ * serviceName: option("--service-name", string()),
249
+ * apiToken: deferredValue(
250
+ * option("--api-token", string()),
251
+ * ({ serviceName }: { readonly serviceName: string }) =>
252
+ * promptForApiToken(serviceName),
253
+ * ),
254
+ * });
255
+ *
256
+ * const parsed = parse(parser, argv);
257
+ * // The prompt only runs if this branch is reached.
258
+ * const apiToken = await parsed.apiToken({
259
+ * serviceName: parsed.serviceName,
260
+ * });
261
+ * ```
262
+ *
263
+ * @template M The execution mode of the wrapped parser.
264
+ * @template T The resolved value type.
265
+ * @template S The state type of the wrapped parser.
266
+ * @param parser The parser that reads the CLI value.
267
+ * @param fallback A resolver run at handler time when no value was specified.
268
+ * @param options Optional {@link DeferredValueOptions}.
269
+ * @returns A parser whose value is a {@link DeferredValue}.
270
+ * @since 1.2.0
271
+ */
272
+ declare function deferredValue<M extends Mode, T, S>(parser: Parser<M, T, S>, fallback: () => T | Promise<T>, options?: DeferredValueOptions): FluentParser<M, DeferredValue<T>, [S] | undefined>;
273
+ declare function deferredValue<M extends Mode, T, S, C>(parser: Parser<M, T, S>, fallback: (ctx: C) => T | Promise<T>, options?: DeferredValueOptions): FluentParser<M, DeferredValue<T, C>, [S] | undefined>;
274
+ /**
275
+ * Checks whether a value is a {@link DeferredValue} produced by
276
+ * {@link deferredValue}.
277
+ *
278
+ * Useful for tests, generic result walkers, and debugging code that only has an
279
+ * `unknown` value. In ordinary code the static type already indicates whether a
280
+ * field is a {@link DeferredValue}.
281
+ *
282
+ * @param value The value to check.
283
+ * @returns `true` if `value` is a {@link DeferredValue}.
284
+ * @since 1.2.0
285
+ */
286
+ declare function isDeferredValue(value: unknown): value is DeferredValue<unknown>;
183
287
  /**
184
288
  * Options for the {@link multiple} parser.
185
289
  */
@@ -306,6 +410,15 @@ interface ParserModifiers<M extends Mode = "sync", TValue = unknown, TState = un
306
410
  * @returns A parser that produces this parser's value or the default value.
307
411
  */
308
412
  withDefault<const TDefault = TValue>(defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): FluentParser<M, TValue | TDefault, [TState] | undefined>;
413
+ /**
414
+ * Defers this parser's value so the command handler resolves it.
415
+ *
416
+ * @param fallback A resolver run at handler time when no value was specified.
417
+ * @param options Optional {@link DeferredValueOptions}.
418
+ * @returns A parser whose value is a {@link DeferredValue}.
419
+ */
420
+ deferredValue(fallback: () => TValue | Promise<TValue>, options?: DeferredValueOptions): FluentParser<M, DeferredValue<TValue>, [TState] | undefined>;
421
+ deferredValue<C>(fallback: (ctx: C) => TValue | Promise<TValue>, options?: DeferredValueOptions): FluentParser<M, DeferredValue<TValue, C>, [TState] | undefined>;
309
422
  /**
310
423
  * Allows this parser to match multiple times.
311
424
  *
@@ -343,4 +456,4 @@ type FluentParser<M extends Mode = "sync", TValue = unknown, TState = unknown> =
343
456
  */
344
457
  declare function fluent<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>): FluentParser<M, TValue, TState>;
345
458
  //#endregion
346
- export { FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, fluent, map, multiple, nonEmpty, optional, withDefault };
459
+ export { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, deferredValue, fluent, isDeferredValue, map, multiple, nonEmpty, optional, withDefault };
package/dist/modifiers.js CHANGED
@@ -845,6 +845,93 @@ function map(parser, transform) {
845
845
  }
846
846
  return fluent(mappedParser);
847
847
  }
848
+ const deferredValueBrand = Symbol.for("@optique/core/deferredValue");
849
+ /**
850
+ * Brands a value-producing function as a {@link DeferredValue}.
851
+ *
852
+ * The brand is a hidden, non-enumerable symbol so {@link isDeferredValue} can
853
+ * recognize the value while object inspection only sees `source`. The `source`
854
+ * property is enumerable but readonly and non-configurable.
855
+ *
856
+ * @param call The value-producing function.
857
+ * @param source The branch that produced the value.
858
+ * @returns The same function decorated as a {@link DeferredValue}.
859
+ */
860
+ function brandDeferredValue(call, source) {
861
+ Object.defineProperties(call, {
862
+ [deferredValueBrand]: {
863
+ value: true,
864
+ enumerable: false,
865
+ writable: false,
866
+ configurable: false
867
+ },
868
+ source: {
869
+ value: source,
870
+ enumerable: true,
871
+ writable: false,
872
+ configurable: false
873
+ }
874
+ });
875
+ return call;
876
+ }
877
+ /**
878
+ * Builds the `"specified"` branch: a function that returns the parsed value
879
+ * and ignores any handler-time context.
880
+ */
881
+ function makeSpecifiedDeferredValue(value) {
882
+ return brandDeferredValue((_ctx) => value, "specified");
883
+ }
884
+ /**
885
+ * Builds the `"fallback"` branch: a function that runs the fallback resolver,
886
+ * optionally memoizing the resolved value or in-flight promise.
887
+ */
888
+ function makeFallbackDeferredValue(fallback, memoize) {
889
+ if (!memoize) return brandDeferredValue((ctx) => fallback(ctx), "fallback");
890
+ let settled = false;
891
+ let settledValue;
892
+ let inFlight;
893
+ const call = (ctx) => {
894
+ if (settled) return settledValue;
895
+ if (inFlight != null) return inFlight;
896
+ const result = fallback(ctx);
897
+ if (!isPromiseLike(result)) {
898
+ settled = true;
899
+ settledValue = result;
900
+ return result;
901
+ }
902
+ const promise = Promise.resolve(result).then((resolved) => {
903
+ settled = true;
904
+ settledValue = resolved;
905
+ inFlight = void 0;
906
+ return resolved;
907
+ }, (error) => {
908
+ inFlight = void 0;
909
+ throw error;
910
+ });
911
+ inFlight = promise;
912
+ return promise;
913
+ };
914
+ return brandDeferredValue(call, "fallback");
915
+ }
916
+ function deferredValue(parser, fallback, options) {
917
+ const memoize = options?.memoize ?? false;
918
+ return map(optional(map(parser, (value) => ({ value }))), (matched) => matched === void 0 ? makeFallbackDeferredValue(fallback, memoize) : makeSpecifiedDeferredValue(matched.value));
919
+ }
920
+ /**
921
+ * Checks whether a value is a {@link DeferredValue} produced by
922
+ * {@link deferredValue}.
923
+ *
924
+ * Useful for tests, generic result walkers, and debugging code that only has an
925
+ * `unknown` value. In ordinary code the static type already indicates whether a
926
+ * field is a {@link DeferredValue}.
927
+ *
928
+ * @param value The value to check.
929
+ * @returns `true` if `value` is a {@link DeferredValue}.
930
+ * @since 1.2.0
931
+ */
932
+ function isDeferredValue(value) {
933
+ return typeof value === "function" && value[deferredValueBrand] === true;
934
+ }
848
935
  /**
849
936
  * Creates a parser that allows multiple occurrences of a given parser.
850
937
  * This parser can be used to parse multiple values of the same type,
@@ -1643,10 +1730,17 @@ function fluent(parser) {
1643
1730
  },
1644
1731
  configurable: true,
1645
1732
  enumerable: false
1733
+ },
1734
+ deferredValue: {
1735
+ value(fallback, options) {
1736
+ return deferredValue(parser, fallback, options);
1737
+ },
1738
+ configurable: true,
1739
+ enumerable: false
1646
1740
  }
1647
1741
  });
1648
1742
  return fluentParser;
1649
1743
  }
1650
1744
 
1651
1745
  //#endregion
1652
- export { WithDefaultError, fluent, map, multiple, nonEmpty, optional, withDefault };
1746
+ export { WithDefaultError, deferredValue, fluent, isDeferredValue, map, multiple, nonEmpty, optional, withDefault };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.2.0-dev.2229",
3
+ "version": "1.2.0-dev.2232",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -208,7 +208,7 @@
208
208
  "fast-check": "^4.7.0",
209
209
  "tsdown": "^0.13.0",
210
210
  "typescript": "^5.8.3",
211
- "@optique/env": "1.2.0-dev.2229+c0eb0d92"
211
+ "@optique/env": "1.2.0-dev.2232+9fc28f44"
212
212
  },
213
213
  "scripts": {
214
214
  "build": "tsdown",