@optique/core 1.4.0-dev.2962 → 1.4.0-dev.2964
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 +0 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/valueparser.cjs +1 -267
- package/dist/valueparser.d.cts +1 -134
- package/dist/valueparser.d.ts +1 -134
- package/dist/valueparser.js +3 -268
- package/package.json +2 -2
- package/skills/optique/SKILL.md +3 -3
package/dist/index.cjs
CHANGED
|
@@ -139,5 +139,4 @@ exports.value = require_message.value;
|
|
|
139
139
|
exports.valueSet = require_message.valueSet;
|
|
140
140
|
exports.values = require_message.values;
|
|
141
141
|
exports.withDefault = require_modifiers.withDefault;
|
|
142
|
-
exports.withSuggestions = require_valueparser.withSuggestions;
|
|
143
142
|
exports.zsh = require_completion.zsh;
|
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ import { Message, MessageFormatOptions, MessageFormatter, MessageFormatterOption
|
|
|
4
4
|
import { ErrorLabelTerm, LabelTerm, ProgramNameTerm, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, defaultTerminalTheme } from "./terminal.cjs";
|
|
5
5
|
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
|
|
6
6
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, EnvironmentBindingDoc, ShowAliasesOptions, ShowChoicesOptions, ShowDefaultOptions, ShowEnvironmentOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, deriveEnvironmentSection, formatDocPage, isDocEntryHidden } from "./doc.cjs";
|
|
7
|
-
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, OriginOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, RegExpOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions,
|
|
7
|
+
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, OriginOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, RegExpOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, TransformMapping, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, biject, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, normalizeInput, origin, port, portRange, regExp, semVer, socketAddress, string, transform, url, uuid } from "./valueparser.cjs";
|
|
8
8
|
import { CombineModes, DetailedParseResult, DocState, EffectfulCompletionSession, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, Parser, ParserContext, ParserResult, Result, Suggestion, createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseDetailed, parseSync, suggest, suggestAsync, suggestSync } from "./internal/parser.cjs";
|
|
9
9
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
10
10
|
import { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, deferredValue, fluent, isDeferredValue, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
|
|
@@ -13,4 +13,4 @@ import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./c
|
|
|
13
13
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, getDependencySourceInfo, isDependencySource, isDerivedValueParser } from "./internal/dependency.cjs";
|
|
14
14
|
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, HelpSectionsOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
|
|
15
15
|
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";
|
|
16
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, EnvironmentBindingDoc, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HelpSectionsOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowAliasesOptions, ShowChoicesOptions, ShowDefaultOptions, ShowEnvironmentOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion,
|
|
16
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, EnvironmentBindingDoc, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HelpSectionsOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowAliasesOptions, ShowChoicesOptions, ShowDefaultOptions, ShowEnvironmentOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, TransformMapping, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveEnvironmentSection, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, 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, normalizeInput, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Message, MessageFormatOptions, MessageFormatter, MessageFormatterOption
|
|
|
4
4
|
import { ErrorLabelTerm, LabelTerm, ProgramNameTerm, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, defaultTerminalTheme } from "./terminal.js";
|
|
5
5
|
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
6
6
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, EnvironmentBindingDoc, ShowAliasesOptions, ShowChoicesOptions, ShowDefaultOptions, ShowEnvironmentOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, deriveEnvironmentSection, formatDocPage, isDocEntryHidden } from "./doc.js";
|
|
7
|
-
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, OriginOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, RegExpOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions,
|
|
7
|
+
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, OriginOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, RegExpOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, TransformMapping, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, biject, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, normalizeInput, origin, port, portRange, regExp, semVer, socketAddress, string, transform, url, uuid } from "./valueparser.js";
|
|
8
8
|
import { CombineModes, DetailedParseResult, DocState, EffectfulCompletionSession, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, Parser, ParserContext, ParserResult, Result, Suggestion, createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseDetailed, parseSync, suggest, suggestAsync, suggestSync } from "./internal/parser.js";
|
|
9
9
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
10
10
|
import { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, deferredValue, fluent, isDeferredValue, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
@@ -13,4 +13,4 @@ import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./c
|
|
|
13
13
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, getDependencySourceInfo, isDependencySource, isDerivedValueParser } from "./internal/dependency.js";
|
|
14
14
|
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, HelpSectionsOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
15
15
|
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";
|
|
16
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, EnvironmentBindingDoc, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HelpSectionsOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowAliasesOptions, ShowChoicesOptions, ShowDefaultOptions, ShowEnvironmentOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion,
|
|
16
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, EnvironmentBindingDoc, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HelpSectionsOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowAliasesOptions, ShowChoicesOptions, ShowDefaultOptions, ShowEnvironmentOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, TransformMapping, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveEnvironmentSection, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, 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, normalizeInput, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/index.js
CHANGED
|
@@ -9,8 +9,8 @@ import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
|
9
9
|
import { WithDefaultError, deferredValue, fluent, isDeferredValue, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
10
10
|
import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, seq, tuple } from "./constructs.js";
|
|
11
11
|
import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
12
|
-
import { biject, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, normalizeInput, origin, port, portRange, regExp, semVer, socketAddress, string, transform, url, uuid
|
|
12
|
+
import { biject, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, normalizeInput, origin, port, portRange, regExp, semVer, socketAddress, string, transform, url, uuid } from "./valueparser.js";
|
|
13
13
|
import { argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.js";
|
|
14
14
|
import { RunParserError, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
15
15
|
|
|
16
|
-
export { DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveEnvironmentSection, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, 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, normalizeInput, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault,
|
|
16
|
+
export { DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveEnvironmentSection, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, 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, normalizeInput, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/valueparser.cjs
CHANGED
|
@@ -415,271 +415,6 @@ function preserveNormalizedDerivedMetadata(wrapped, parser, normalize) {
|
|
|
415
415
|
});
|
|
416
416
|
}
|
|
417
417
|
}
|
|
418
|
-
function withSuggestions(parser, options) {
|
|
419
|
-
if (!isValueParser(parser)) throw new TypeError("Expected parser to be a value parser.");
|
|
420
|
-
if (options == null || typeof options !== "object") throw new TypeError("Expected options to be an object.");
|
|
421
|
-
if (typeof options.suggest !== "function") throw new TypeError("Expected suggest to be a function.");
|
|
422
|
-
checkEnumOption(options, "mode", ["sync", "async"]);
|
|
423
|
-
checkBooleanOption(options, "includeExisting");
|
|
424
|
-
checkBooleanOption(options, "filterByPrefix");
|
|
425
|
-
if (require_internal_dependency.isDependencySource(parser)) throw new TypeError("Cannot attach suggestions to a dependency source directly.");
|
|
426
|
-
const inner = parser;
|
|
427
|
-
const providerMode = options.mode ?? "sync";
|
|
428
|
-
const resultMode = providerMode === "async" ? "async" : inner.mode;
|
|
429
|
-
const lift = resultMode !== inner.mode;
|
|
430
|
-
const provider = options.suggest;
|
|
431
|
-
const includeExisting = options.includeExisting ?? false;
|
|
432
|
-
const filterByPrefix = options.filterByPrefix ?? true;
|
|
433
|
-
const existingSuggest = includeExisting ? inner.suggest?.bind(inner) : void 0;
|
|
434
|
-
const normalizeValue = inner.normalize?.bind(inner);
|
|
435
|
-
const validate = inner.validate?.bind(inner);
|
|
436
|
-
const getProviderSource = (prefix) => () => {
|
|
437
|
-
const source = provider(prefix);
|
|
438
|
-
return providerMode === "sync" ? checkSyncProviderResult(source) : source;
|
|
439
|
-
};
|
|
440
|
-
const suggestFrom = (prefix, existing) => require_mode_dispatch.dispatchIterableByMode(resultMode, () => suggestFromSources(createSuggestionProcessors(prefix, filterByPrefix), existing, getProviderSource(prefix)), () => suggestFromSourcesAsync(createSuggestionProcessors(prefix, filterByPrefix), existing, getProviderSource(prefix)));
|
|
441
|
-
const wrapped = {
|
|
442
|
-
mode: resultMode,
|
|
443
|
-
metavar: inner.metavar,
|
|
444
|
-
get placeholder() {
|
|
445
|
-
return inner.placeholder;
|
|
446
|
-
},
|
|
447
|
-
...inner.choices == null ? {} : { choices: inner.choices },
|
|
448
|
-
parse(input) {
|
|
449
|
-
return lift ? liftToAsync(() => inner.parse(input)) : inner.parse(input);
|
|
450
|
-
},
|
|
451
|
-
format(value) {
|
|
452
|
-
return inner.format(value);
|
|
453
|
-
},
|
|
454
|
-
...normalizeValue == null ? {} : { normalize(value) {
|
|
455
|
-
return normalizeValue(value);
|
|
456
|
-
} },
|
|
457
|
-
...validate == null ? {} : { validate(value) {
|
|
458
|
-
return validate(value);
|
|
459
|
-
} },
|
|
460
|
-
suggest(prefix) {
|
|
461
|
-
return suggestFrom(prefix, existingSuggest == null ? void 0 : () => existingSuggest(prefix));
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
const docValue = require_internal_doc_metadata.getDocValue(inner);
|
|
465
|
-
if (docValue != null) require_internal_doc_metadata.captureDocValue(wrapped, docValue);
|
|
466
|
-
if (require_internal_dependency.isDerivedValueParser(inner)) preserveSuggestedDerivedMetadata(wrapped, inner, lift, includeExisting, suggestFrom);
|
|
467
|
-
return wrapped;
|
|
468
|
-
}
|
|
469
|
-
function preserveSuggestedDerivedMetadata(wrapped, parser, lift, includeExisting, suggestFrom) {
|
|
470
|
-
Object.defineProperties(wrapped, {
|
|
471
|
-
[require_internal_dependency.derivedValueParserMarker]: {
|
|
472
|
-
value: true,
|
|
473
|
-
enumerable: true
|
|
474
|
-
},
|
|
475
|
-
[require_internal_dependency.dependencyId]: {
|
|
476
|
-
value: parser[require_internal_dependency.dependencyId],
|
|
477
|
-
enumerable: true
|
|
478
|
-
},
|
|
479
|
-
[require_internal_dependency.parseWithDependency]: {
|
|
480
|
-
value(input, dependencyValue) {
|
|
481
|
-
return lift ? liftToAsync(() => parser[require_internal_dependency.parseWithDependency](input, dependencyValue)) : parser[require_internal_dependency.parseWithDependency](input, dependencyValue);
|
|
482
|
-
},
|
|
483
|
-
enumerable: true
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
if (require_internal_dependency.dependencyIds in parser && parser[require_internal_dependency.dependencyIds] != null) Object.defineProperty(wrapped, require_internal_dependency.dependencyIds, {
|
|
487
|
-
value: parser[require_internal_dependency.dependencyIds],
|
|
488
|
-
enumerable: true
|
|
489
|
-
});
|
|
490
|
-
if (require_internal_dependency.defaultValues in parser && parser[require_internal_dependency.defaultValues] != null) Object.defineProperty(wrapped, require_internal_dependency.defaultValues, {
|
|
491
|
-
value: parser[require_internal_dependency.defaultValues],
|
|
492
|
-
enumerable: true
|
|
493
|
-
});
|
|
494
|
-
if (require_internal_dependency.singleDefaultValue in parser && parser[require_internal_dependency.singleDefaultValue] != null) Object.defineProperty(wrapped, require_internal_dependency.singleDefaultValue, {
|
|
495
|
-
value: parser[require_internal_dependency.singleDefaultValue],
|
|
496
|
-
enumerable: true
|
|
497
|
-
});
|
|
498
|
-
if (includeExisting && require_internal_dependency.suggestWithDependency in parser && parser[require_internal_dependency.suggestWithDependency] != null) {
|
|
499
|
-
const existing = parser[require_internal_dependency.suggestWithDependency].bind(parser);
|
|
500
|
-
Object.defineProperty(wrapped, require_internal_dependency.suggestWithDependency, {
|
|
501
|
-
value(prefix, dependencyValue) {
|
|
502
|
-
return suggestFrom(prefix, () => existing(prefix, dependencyValue));
|
|
503
|
-
},
|
|
504
|
-
enumerable: true
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* Lifts a synchronous computation to async mode. It runs inside an async
|
|
510
|
-
* function, so a synchronous throw becomes a rejected promise, and the
|
|
511
|
-
* resolved result object is passed through unchanged.
|
|
512
|
-
*/
|
|
513
|
-
function liftToAsync(compute) {
|
|
514
|
-
return require_mode_dispatch.dispatchByMode("async", () => require_mode_dispatch.wrapForMode("sync", compute()), async () => await compute());
|
|
515
|
-
}
|
|
516
|
-
function isThenable(value) {
|
|
517
|
-
return isObjectLike(value) && "then" in value && typeof value.then === "function";
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Rejects results a synchronous provider must not return, even when the
|
|
521
|
-
* resulting parser is async. A thenable gets a rejection handler first so
|
|
522
|
-
* that an invalid async callback cannot cause an unhandled rejection.
|
|
523
|
-
* @throws {TypeError} If the result is not a synchronous iterable.
|
|
524
|
-
*/
|
|
525
|
-
function checkSyncProviderResult(source) {
|
|
526
|
-
if (isThenable(source)) {
|
|
527
|
-
Promise.resolve(source).then(void 0, () => {});
|
|
528
|
-
throw new TypeError("A sync suggestion provider returned a promise.");
|
|
529
|
-
}
|
|
530
|
-
return { [Symbol.iterator]: getSyncIteratorMethod(source) };
|
|
531
|
-
}
|
|
532
|
-
function isObjectLike(value) {
|
|
533
|
-
return value != null && (typeof value === "object" || typeof value === "function");
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* @throws {TypeError} If the source is not a non-string iterable.
|
|
537
|
-
*/
|
|
538
|
-
function getSyncIteratorMethod(source) {
|
|
539
|
-
if (!isObjectLike(source) || !(Symbol.iterator in source) || typeof source[Symbol.iterator] !== "function") throw new TypeError("Expected an iterable of suggestions.");
|
|
540
|
-
const iterable = source;
|
|
541
|
-
return () => iterable[Symbol.iterator]();
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* @throws {TypeError} If the source is not a non-string iterable.
|
|
545
|
-
*/
|
|
546
|
-
function getSyncIterator(source) {
|
|
547
|
-
return getSyncIteratorMethod(source)();
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* @throws {TypeError} If the source is neither an async iterable nor a
|
|
551
|
-
* non-string iterable.
|
|
552
|
-
*/
|
|
553
|
-
function getAnyIterator(source) {
|
|
554
|
-
if (isObjectLike(source) && Symbol.asyncIterator in source && typeof source[Symbol.asyncIterator] === "function") {
|
|
555
|
-
const iterable = source;
|
|
556
|
-
return iterable[Symbol.asyncIterator]();
|
|
557
|
-
}
|
|
558
|
-
return getSyncIterator(source);
|
|
559
|
-
}
|
|
560
|
-
const fileSuggestionTypes = new Set([
|
|
561
|
-
"file",
|
|
562
|
-
"directory",
|
|
563
|
-
"any"
|
|
564
|
-
]);
|
|
565
|
-
function isOptionalOfType(item, key, check) {
|
|
566
|
-
const value = Reflect.get(item, key);
|
|
567
|
-
return value === void 0 || check(value);
|
|
568
|
-
}
|
|
569
|
-
function isString(value) {
|
|
570
|
-
return typeof value === "string";
|
|
571
|
-
}
|
|
572
|
-
function isStringArray(value) {
|
|
573
|
-
return Array.isArray(value) && value.every(isString);
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
* Screens a provider item for the `Suggestion` fields that completion encoding
|
|
577
|
-
* relies on: required fields and the types of optional ones. This is shape
|
|
578
|
-
* checking, not full validation; message terms inside a description are
|
|
579
|
-
* trusted.
|
|
580
|
-
*/
|
|
581
|
-
function screenSuggestionInput(item) {
|
|
582
|
-
if (typeof item === "string") return {
|
|
583
|
-
kind: "literal",
|
|
584
|
-
text: item
|
|
585
|
-
};
|
|
586
|
-
if (item == null || typeof item !== "object" || !("kind" in item)) return void 0;
|
|
587
|
-
if (!isOptionalOfType(item, "description", Array.isArray)) return void 0;
|
|
588
|
-
if (item.kind === "literal") return "text" in item && typeof item.text === "string" ? item : void 0;
|
|
589
|
-
if (item.kind === "file") return "type" in item && fileSuggestionTypes.has(item.type) && isOptionalOfType(item, "pattern", isString) && isOptionalOfType(item, "prefix", isString) && isOptionalOfType(item, "extensions", isStringArray) && isOptionalOfType(item, "includeHidden", (value) => typeof value === "boolean") ? item : void 0;
|
|
590
|
-
return void 0;
|
|
591
|
-
}
|
|
592
|
-
function createSuggestionProcessors(prefix, filterByPrefix) {
|
|
593
|
-
const seen = /* @__PURE__ */ new Set();
|
|
594
|
-
const dedupe = (suggestion) => {
|
|
595
|
-
if (suggestion.kind !== "literal") return suggestion;
|
|
596
|
-
if (seen.has(suggestion.text)) return void 0;
|
|
597
|
-
seen.add(suggestion.text);
|
|
598
|
-
return suggestion;
|
|
599
|
-
};
|
|
600
|
-
return {
|
|
601
|
-
existing: (item) => dedupe(item),
|
|
602
|
-
provider(item) {
|
|
603
|
-
const suggestion = screenSuggestionInput(item);
|
|
604
|
-
if (suggestion == null || filterByPrefix && suggestion.kind === "literal" && !suggestion.text.startsWith(prefix)) return void 0;
|
|
605
|
-
return dedupe(suggestion);
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
function* suggestFromSources(processors, existing, provider) {
|
|
610
|
-
if (existing != null) yield* guardedSuggestions(existing, processors.existing);
|
|
611
|
-
yield* guardedSuggestions(provider, processors.provider);
|
|
612
|
-
}
|
|
613
|
-
async function* suggestFromSourcesAsync(processors, existing, provider) {
|
|
614
|
-
if (existing != null) yield* guardedSuggestionsAsync(existing, processors.existing);
|
|
615
|
-
yield* guardedSuggestionsAsync(provider, processors.provider);
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Yields processed items from one source, ending quietly on any failure.
|
|
619
|
-
* Yields happen outside the guarded regions, so consumer cancellation is never
|
|
620
|
-
* mistaken for a source failure, and the source iterator is closed when the
|
|
621
|
-
* consumer stops early.
|
|
622
|
-
*/
|
|
623
|
-
function* guardedSuggestions(getSource, process) {
|
|
624
|
-
let iterator;
|
|
625
|
-
try {
|
|
626
|
-
iterator = getSyncIterator(getSource());
|
|
627
|
-
} catch {
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
let finished = false;
|
|
631
|
-
try {
|
|
632
|
-
while (true) {
|
|
633
|
-
let suggestion;
|
|
634
|
-
try {
|
|
635
|
-
const step = iterator.next();
|
|
636
|
-
if (!isObjectLike(step)) return;
|
|
637
|
-
if (step.done) {
|
|
638
|
-
finished = true;
|
|
639
|
-
return;
|
|
640
|
-
}
|
|
641
|
-
suggestion = process(step.value);
|
|
642
|
-
} catch {
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
if (suggestion != null) yield suggestion;
|
|
646
|
-
}
|
|
647
|
-
} finally {
|
|
648
|
-
if (!finished) try {
|
|
649
|
-
iterator.return?.();
|
|
650
|
-
} catch {}
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
async function* guardedSuggestionsAsync(getSource, process) {
|
|
654
|
-
let iterator;
|
|
655
|
-
try {
|
|
656
|
-
iterator = getAnyIterator(await getSource());
|
|
657
|
-
} catch {
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
let finished = false;
|
|
661
|
-
try {
|
|
662
|
-
while (true) {
|
|
663
|
-
let suggestion;
|
|
664
|
-
try {
|
|
665
|
-
const step = await iterator.next();
|
|
666
|
-
if (!isObjectLike(step)) return;
|
|
667
|
-
if (step.done) {
|
|
668
|
-
finished = true;
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
suggestion = process(step.value);
|
|
672
|
-
} catch {
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
if (suggestion != null) yield suggestion;
|
|
676
|
-
}
|
|
677
|
-
} finally {
|
|
678
|
-
if (!finished) try {
|
|
679
|
-
await iterator.return?.();
|
|
680
|
-
} catch {}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
418
|
/**
|
|
684
419
|
* Creates a value parser that transforms the result of another value parser.
|
|
685
420
|
*
|
|
@@ -7291,5 +7026,4 @@ exports.socketAddress = socketAddress;
|
|
|
7291
7026
|
exports.string = string;
|
|
7292
7027
|
exports.transform = transform;
|
|
7293
7028
|
exports.url = url;
|
|
7294
|
-
exports.uuid = uuid;
|
|
7295
|
-
exports.withSuggestions = withSuggestions;
|
|
7029
|
+
exports.uuid = uuid;
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -459,139 +459,6 @@ declare function biject<const T extends object>(mapping: T): ValueParser<"sync",
|
|
|
459
459
|
* @since 1.4.0
|
|
460
460
|
*/
|
|
461
461
|
declare function normalizeInput<M extends Mode, T>(parser: ValueParser<M, T>, normalize: (input: string) => string): ValueParser<M, T>;
|
|
462
|
-
/**
|
|
463
|
-
* A completion candidate produced by a {@link withSuggestions} provider.
|
|
464
|
-
*
|
|
465
|
-
* A string is shorthand for a literal suggestion with that text.
|
|
466
|
-
*
|
|
467
|
-
* @since 1.4.0
|
|
468
|
-
*/
|
|
469
|
-
type SuggestionInput = string | Suggestion;
|
|
470
|
-
/**
|
|
471
|
-
* Options shared by every {@link withSuggestions} provider mode.
|
|
472
|
-
*
|
|
473
|
-
* @since 1.4.0
|
|
474
|
-
*/
|
|
475
|
-
interface WithSuggestionsOptionsBase {
|
|
476
|
-
/**
|
|
477
|
-
* Whether to keep the wrapped parser's own suggestions. When `true`, they
|
|
478
|
-
* are produced first, followed by the provider's candidates. Literal
|
|
479
|
-
* candidates whose text was already produced are skipped.
|
|
480
|
-
*
|
|
481
|
-
* @default `false`
|
|
482
|
-
*/
|
|
483
|
-
readonly includeExisting?: boolean;
|
|
484
|
-
/**
|
|
485
|
-
* Whether to drop provider literals whose text does not start with the
|
|
486
|
-
* completion prefix. Turn this off when the provider already matches in
|
|
487
|
-
* its own way, such as case-insensitively or by completing `42` to `#42`,
|
|
488
|
-
* and returns spellings that differ from the typed prefix. Suggestions
|
|
489
|
-
* kept by `includeExisting` are never filtered by this wrapper.
|
|
490
|
-
*
|
|
491
|
-
* @default `true`
|
|
492
|
-
*/
|
|
493
|
-
readonly filterByPrefix?: boolean;
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Options for {@link withSuggestions} with a synchronous provider.
|
|
497
|
-
*
|
|
498
|
-
* @since 1.4.0
|
|
499
|
-
*/
|
|
500
|
-
interface WithSuggestionsSyncOptions extends WithSuggestionsOptionsBase {
|
|
501
|
-
/**
|
|
502
|
-
* The provider mode. Synchronous providers keep the wrapped parser's mode.
|
|
503
|
-
*
|
|
504
|
-
* @default `"sync"`
|
|
505
|
-
*/
|
|
506
|
-
readonly mode?: "sync";
|
|
507
|
-
/**
|
|
508
|
-
* Returns completion candidates for the given prefix. This is a shell
|
|
509
|
-
* completion provider, unrelated to the typo hints configured by
|
|
510
|
-
* `choice()`'s `suggest` option. It is called only during completion,
|
|
511
|
-
* never while parsing. Failures are swallowed without logging, so log
|
|
512
|
-
* inside the provider if you need diagnostics.
|
|
513
|
-
*
|
|
514
|
-
* Return a collection of candidates, not a bare string: a string result
|
|
515
|
-
* yields no suggestions rather than one suggestion per character.
|
|
516
|
-
*
|
|
517
|
-
* @param prefix The current input prefix to complete.
|
|
518
|
-
* @returns The completion candidates.
|
|
519
|
-
*/
|
|
520
|
-
readonly suggest: (prefix: string) => Iterable<SuggestionInput>;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Options for {@link withSuggestions} with an asynchronous provider.
|
|
524
|
-
*
|
|
525
|
-
* @since 1.4.0
|
|
526
|
-
*/
|
|
527
|
-
interface WithSuggestionsAsyncOptions extends WithSuggestionsOptionsBase {
|
|
528
|
-
/**
|
|
529
|
-
* The provider mode. Asynchronous providers make the resulting value
|
|
530
|
-
* parser asynchronous.
|
|
531
|
-
*/
|
|
532
|
-
readonly mode: "async";
|
|
533
|
-
/**
|
|
534
|
-
* Returns completion candidates for the given prefix. It may be an async
|
|
535
|
-
* generator, or return an iterable, an async iterable, or a promise of
|
|
536
|
-
* either. This is a shell completion provider, unrelated to the typo hints
|
|
537
|
-
* configured by `choice()`'s `suggest` option. It is called only during
|
|
538
|
-
* completion, never while parsing. Failures are swallowed without logging,
|
|
539
|
-
* so log inside the provider if you need diagnostics. A bare string result
|
|
540
|
-
* yields no suggestions.
|
|
541
|
-
*
|
|
542
|
-
* @param prefix The current input prefix to complete.
|
|
543
|
-
* @returns The completion candidates.
|
|
544
|
-
*/
|
|
545
|
-
readonly suggest: (prefix: string) => Iterable<SuggestionInput> | AsyncIterable<SuggestionInput> | Promise<Iterable<SuggestionInput> | AsyncIterable<SuggestionInput>>;
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Options for {@link withSuggestions}.
|
|
549
|
-
*
|
|
550
|
-
* @since 1.4.0
|
|
551
|
-
*/
|
|
552
|
-
type WithSuggestionsOptions = WithSuggestionsSyncOptions | WithSuggestionsAsyncOptions;
|
|
553
|
-
/**
|
|
554
|
-
* Attaches completion candidates to an existing value parser.
|
|
555
|
-
*
|
|
556
|
-
* The returned parser accepts the same input and produces the same values as
|
|
557
|
-
* `parser`: parsing, formatting, `normalize()`, `validate()`, `choices`,
|
|
558
|
-
* the placeholder, and dependency-derived behavior are all delegated to it.
|
|
559
|
-
* Only `suggest()` changes. By default the provider's candidates replace the
|
|
560
|
-
* wrapped parser's own suggestions; set `includeExisting` to keep them.
|
|
561
|
-
*
|
|
562
|
-
* The provider receives the raw completion prefix, so it can filter on the
|
|
563
|
-
* server side, and literal candidates that do not start with the prefix are
|
|
564
|
-
* dropped afterwards unless `filterByPrefix` is `false`. Completion is best-effort: if the provider throws,
|
|
565
|
-
* rejects, or fails during iteration, candidates produced so far are kept and
|
|
566
|
-
* the rest are skipped. Malformed candidates are skipped.
|
|
567
|
-
*
|
|
568
|
-
* A synchronous provider keeps the wrapped parser's mode. An asynchronous
|
|
569
|
-
* provider (`mode: "async"`) makes the result asynchronous, so `parse()`
|
|
570
|
-
* returns a promise even when the wrapped parser is synchronous.
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```typescript
|
|
574
|
-
* const issue = withSuggestions(integer({ min: 1 }), {
|
|
575
|
-
* mode: "async",
|
|
576
|
-
* async *suggest(prefix) {
|
|
577
|
-
* yield* await listIssueNumbers(prefix);
|
|
578
|
-
* },
|
|
579
|
-
* });
|
|
580
|
-
* ```
|
|
581
|
-
*
|
|
582
|
-
* @template M The mode of the wrapped parser.
|
|
583
|
-
* @template T The value type produced by the wrapped parser.
|
|
584
|
-
* @param parser The value parser to attach suggestions to.
|
|
585
|
-
* @param options The completion provider and its options.
|
|
586
|
-
* @returns A value parser that accepts the same input as `parser` and uses the
|
|
587
|
-
* provider for completion.
|
|
588
|
-
* @throws {TypeError} If `parser` is not a value parser or is a dependency
|
|
589
|
-
* source, or if `options` is invalid.
|
|
590
|
-
* @since 1.4.0
|
|
591
|
-
*/
|
|
592
|
-
declare function withSuggestions<M extends Mode, T>(parser: ValueParser<M, T>, options: WithSuggestionsSyncOptions): ValueParser<M, T>;
|
|
593
|
-
declare function withSuggestions<M extends Mode, T>(parser: ValueParser<M, T>, options: WithSuggestionsAsyncOptions): ValueParser<"async", T>;
|
|
594
|
-
declare function withSuggestions<M extends Mode, T>(parser: ValueParser<M, T>, options: WithSuggestionsOptions): ValueParser<M | "async", T>;
|
|
595
462
|
/**
|
|
596
463
|
* Creates a value parser that transforms the result of another value parser.
|
|
597
464
|
*
|
|
@@ -3590,4 +3457,4 @@ declare function firstOf<const TParsers extends readonly [ValueParser<"sync", un
|
|
|
3590
3457
|
*/
|
|
3591
3458
|
declare function firstOf<const TParsers extends readonly ValueParser<"sync", unknown>[]>(parsers: TParsers, options?: FirstOfOptions): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
3592
3459
|
//#endregion
|
|
3593
|
-
export { 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, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, OriginOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, RegExpOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions,
|
|
3460
|
+
export { 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, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, OriginOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, RegExpOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, TransformMapping, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, biject, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, locale, macAddress, normalizeInput, origin, port, portRange, regExp, semVer, socketAddress, string, transform, url, uuid };
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -459,139 +459,6 @@ declare function biject<const T extends object>(mapping: T): ValueParser<"sync",
|
|
|
459
459
|
* @since 1.4.0
|
|
460
460
|
*/
|
|
461
461
|
declare function normalizeInput<M extends Mode, T>(parser: ValueParser<M, T>, normalize: (input: string) => string): ValueParser<M, T>;
|
|
462
|
-
/**
|
|
463
|
-
* A completion candidate produced by a {@link withSuggestions} provider.
|
|
464
|
-
*
|
|
465
|
-
* A string is shorthand for a literal suggestion with that text.
|
|
466
|
-
*
|
|
467
|
-
* @since 1.4.0
|
|
468
|
-
*/
|
|
469
|
-
type SuggestionInput = string | Suggestion;
|
|
470
|
-
/**
|
|
471
|
-
* Options shared by every {@link withSuggestions} provider mode.
|
|
472
|
-
*
|
|
473
|
-
* @since 1.4.0
|
|
474
|
-
*/
|
|
475
|
-
interface WithSuggestionsOptionsBase {
|
|
476
|
-
/**
|
|
477
|
-
* Whether to keep the wrapped parser's own suggestions. When `true`, they
|
|
478
|
-
* are produced first, followed by the provider's candidates. Literal
|
|
479
|
-
* candidates whose text was already produced are skipped.
|
|
480
|
-
*
|
|
481
|
-
* @default `false`
|
|
482
|
-
*/
|
|
483
|
-
readonly includeExisting?: boolean;
|
|
484
|
-
/**
|
|
485
|
-
* Whether to drop provider literals whose text does not start with the
|
|
486
|
-
* completion prefix. Turn this off when the provider already matches in
|
|
487
|
-
* its own way, such as case-insensitively or by completing `42` to `#42`,
|
|
488
|
-
* and returns spellings that differ from the typed prefix. Suggestions
|
|
489
|
-
* kept by `includeExisting` are never filtered by this wrapper.
|
|
490
|
-
*
|
|
491
|
-
* @default `true`
|
|
492
|
-
*/
|
|
493
|
-
readonly filterByPrefix?: boolean;
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Options for {@link withSuggestions} with a synchronous provider.
|
|
497
|
-
*
|
|
498
|
-
* @since 1.4.0
|
|
499
|
-
*/
|
|
500
|
-
interface WithSuggestionsSyncOptions extends WithSuggestionsOptionsBase {
|
|
501
|
-
/**
|
|
502
|
-
* The provider mode. Synchronous providers keep the wrapped parser's mode.
|
|
503
|
-
*
|
|
504
|
-
* @default `"sync"`
|
|
505
|
-
*/
|
|
506
|
-
readonly mode?: "sync";
|
|
507
|
-
/**
|
|
508
|
-
* Returns completion candidates for the given prefix. This is a shell
|
|
509
|
-
* completion provider, unrelated to the typo hints configured by
|
|
510
|
-
* `choice()`'s `suggest` option. It is called only during completion,
|
|
511
|
-
* never while parsing. Failures are swallowed without logging, so log
|
|
512
|
-
* inside the provider if you need diagnostics.
|
|
513
|
-
*
|
|
514
|
-
* Return a collection of candidates, not a bare string: a string result
|
|
515
|
-
* yields no suggestions rather than one suggestion per character.
|
|
516
|
-
*
|
|
517
|
-
* @param prefix The current input prefix to complete.
|
|
518
|
-
* @returns The completion candidates.
|
|
519
|
-
*/
|
|
520
|
-
readonly suggest: (prefix: string) => Iterable<SuggestionInput>;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Options for {@link withSuggestions} with an asynchronous provider.
|
|
524
|
-
*
|
|
525
|
-
* @since 1.4.0
|
|
526
|
-
*/
|
|
527
|
-
interface WithSuggestionsAsyncOptions extends WithSuggestionsOptionsBase {
|
|
528
|
-
/**
|
|
529
|
-
* The provider mode. Asynchronous providers make the resulting value
|
|
530
|
-
* parser asynchronous.
|
|
531
|
-
*/
|
|
532
|
-
readonly mode: "async";
|
|
533
|
-
/**
|
|
534
|
-
* Returns completion candidates for the given prefix. It may be an async
|
|
535
|
-
* generator, or return an iterable, an async iterable, or a promise of
|
|
536
|
-
* either. This is a shell completion provider, unrelated to the typo hints
|
|
537
|
-
* configured by `choice()`'s `suggest` option. It is called only during
|
|
538
|
-
* completion, never while parsing. Failures are swallowed without logging,
|
|
539
|
-
* so log inside the provider if you need diagnostics. A bare string result
|
|
540
|
-
* yields no suggestions.
|
|
541
|
-
*
|
|
542
|
-
* @param prefix The current input prefix to complete.
|
|
543
|
-
* @returns The completion candidates.
|
|
544
|
-
*/
|
|
545
|
-
readonly suggest: (prefix: string) => Iterable<SuggestionInput> | AsyncIterable<SuggestionInput> | Promise<Iterable<SuggestionInput> | AsyncIterable<SuggestionInput>>;
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Options for {@link withSuggestions}.
|
|
549
|
-
*
|
|
550
|
-
* @since 1.4.0
|
|
551
|
-
*/
|
|
552
|
-
type WithSuggestionsOptions = WithSuggestionsSyncOptions | WithSuggestionsAsyncOptions;
|
|
553
|
-
/**
|
|
554
|
-
* Attaches completion candidates to an existing value parser.
|
|
555
|
-
*
|
|
556
|
-
* The returned parser accepts the same input and produces the same values as
|
|
557
|
-
* `parser`: parsing, formatting, `normalize()`, `validate()`, `choices`,
|
|
558
|
-
* the placeholder, and dependency-derived behavior are all delegated to it.
|
|
559
|
-
* Only `suggest()` changes. By default the provider's candidates replace the
|
|
560
|
-
* wrapped parser's own suggestions; set `includeExisting` to keep them.
|
|
561
|
-
*
|
|
562
|
-
* The provider receives the raw completion prefix, so it can filter on the
|
|
563
|
-
* server side, and literal candidates that do not start with the prefix are
|
|
564
|
-
* dropped afterwards unless `filterByPrefix` is `false`. Completion is best-effort: if the provider throws,
|
|
565
|
-
* rejects, or fails during iteration, candidates produced so far are kept and
|
|
566
|
-
* the rest are skipped. Malformed candidates are skipped.
|
|
567
|
-
*
|
|
568
|
-
* A synchronous provider keeps the wrapped parser's mode. An asynchronous
|
|
569
|
-
* provider (`mode: "async"`) makes the result asynchronous, so `parse()`
|
|
570
|
-
* returns a promise even when the wrapped parser is synchronous.
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```typescript
|
|
574
|
-
* const issue = withSuggestions(integer({ min: 1 }), {
|
|
575
|
-
* mode: "async",
|
|
576
|
-
* async *suggest(prefix) {
|
|
577
|
-
* yield* await listIssueNumbers(prefix);
|
|
578
|
-
* },
|
|
579
|
-
* });
|
|
580
|
-
* ```
|
|
581
|
-
*
|
|
582
|
-
* @template M The mode of the wrapped parser.
|
|
583
|
-
* @template T The value type produced by the wrapped parser.
|
|
584
|
-
* @param parser The value parser to attach suggestions to.
|
|
585
|
-
* @param options The completion provider and its options.
|
|
586
|
-
* @returns A value parser that accepts the same input as `parser` and uses the
|
|
587
|
-
* provider for completion.
|
|
588
|
-
* @throws {TypeError} If `parser` is not a value parser or is a dependency
|
|
589
|
-
* source, or if `options` is invalid.
|
|
590
|
-
* @since 1.4.0
|
|
591
|
-
*/
|
|
592
|
-
declare function withSuggestions<M extends Mode, T>(parser: ValueParser<M, T>, options: WithSuggestionsSyncOptions): ValueParser<M, T>;
|
|
593
|
-
declare function withSuggestions<M extends Mode, T>(parser: ValueParser<M, T>, options: WithSuggestionsAsyncOptions): ValueParser<"async", T>;
|
|
594
|
-
declare function withSuggestions<M extends Mode, T>(parser: ValueParser<M, T>, options: WithSuggestionsOptions): ValueParser<M | "async", T>;
|
|
595
462
|
/**
|
|
596
463
|
* Creates a value parser that transforms the result of another value parser.
|
|
597
464
|
*
|
|
@@ -3590,4 +3457,4 @@ declare function firstOf<const TParsers extends readonly [ValueParser<"sync", un
|
|
|
3590
3457
|
*/
|
|
3591
3458
|
declare function firstOf<const TParsers extends readonly ValueParser<"sync", unknown>[]>(parsers: TParsers, options?: FirstOfOptions): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
3592
3459
|
//#endregion
|
|
3593
|
-
export { 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, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, OriginOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, RegExpOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions,
|
|
3460
|
+
export { 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, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, OriginOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, RegExpOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, TransformMapping, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, biject, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, locale, macAddress, normalizeInput, origin, port, portRange, regExp, semVer, socketAddress, string, transform, url, uuid };
|
package/dist/valueparser.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cloneMessage, lineBreak, message, metavar, text, valueSet } from "./message.js";
|
|
2
|
-
import {
|
|
2
|
+
import { mapMaybePromiseByMode, wrapForMode, wrapIterableForMode } from "./internal/mode-dispatch.js";
|
|
3
3
|
import { defaultValues, dependencyId, dependencyIds, derivedValueParserMarker, getSnapshottedDefaultDependencyValues, isDependencySource, isDerivedValueParser, parseWithDependency, singleDefaultValue, snapshotDefaultDependencyValues, suggestWithDependency } from "./internal/dependency.js";
|
|
4
|
-
import { captureDocValue
|
|
4
|
+
import { captureDocValue } from "./internal/doc-metadata.js";
|
|
5
5
|
import { appendValueHint, appendValueSuggestions, deduplicateSuggestions } from "./suggestion.js";
|
|
6
6
|
import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
7
7
|
|
|
@@ -415,271 +415,6 @@ function preserveNormalizedDerivedMetadata(wrapped, parser, normalize) {
|
|
|
415
415
|
});
|
|
416
416
|
}
|
|
417
417
|
}
|
|
418
|
-
function withSuggestions(parser, options) {
|
|
419
|
-
if (!isValueParser(parser)) throw new TypeError("Expected parser to be a value parser.");
|
|
420
|
-
if (options == null || typeof options !== "object") throw new TypeError("Expected options to be an object.");
|
|
421
|
-
if (typeof options.suggest !== "function") throw new TypeError("Expected suggest to be a function.");
|
|
422
|
-
checkEnumOption(options, "mode", ["sync", "async"]);
|
|
423
|
-
checkBooleanOption(options, "includeExisting");
|
|
424
|
-
checkBooleanOption(options, "filterByPrefix");
|
|
425
|
-
if (isDependencySource(parser)) throw new TypeError("Cannot attach suggestions to a dependency source directly.");
|
|
426
|
-
const inner = parser;
|
|
427
|
-
const providerMode = options.mode ?? "sync";
|
|
428
|
-
const resultMode = providerMode === "async" ? "async" : inner.mode;
|
|
429
|
-
const lift = resultMode !== inner.mode;
|
|
430
|
-
const provider = options.suggest;
|
|
431
|
-
const includeExisting = options.includeExisting ?? false;
|
|
432
|
-
const filterByPrefix = options.filterByPrefix ?? true;
|
|
433
|
-
const existingSuggest = includeExisting ? inner.suggest?.bind(inner) : void 0;
|
|
434
|
-
const normalizeValue = inner.normalize?.bind(inner);
|
|
435
|
-
const validate = inner.validate?.bind(inner);
|
|
436
|
-
const getProviderSource = (prefix) => () => {
|
|
437
|
-
const source = provider(prefix);
|
|
438
|
-
return providerMode === "sync" ? checkSyncProviderResult(source) : source;
|
|
439
|
-
};
|
|
440
|
-
const suggestFrom = (prefix, existing) => dispatchIterableByMode(resultMode, () => suggestFromSources(createSuggestionProcessors(prefix, filterByPrefix), existing, getProviderSource(prefix)), () => suggestFromSourcesAsync(createSuggestionProcessors(prefix, filterByPrefix), existing, getProviderSource(prefix)));
|
|
441
|
-
const wrapped = {
|
|
442
|
-
mode: resultMode,
|
|
443
|
-
metavar: inner.metavar,
|
|
444
|
-
get placeholder() {
|
|
445
|
-
return inner.placeholder;
|
|
446
|
-
},
|
|
447
|
-
...inner.choices == null ? {} : { choices: inner.choices },
|
|
448
|
-
parse(input) {
|
|
449
|
-
return lift ? liftToAsync(() => inner.parse(input)) : inner.parse(input);
|
|
450
|
-
},
|
|
451
|
-
format(value) {
|
|
452
|
-
return inner.format(value);
|
|
453
|
-
},
|
|
454
|
-
...normalizeValue == null ? {} : { normalize(value) {
|
|
455
|
-
return normalizeValue(value);
|
|
456
|
-
} },
|
|
457
|
-
...validate == null ? {} : { validate(value) {
|
|
458
|
-
return validate(value);
|
|
459
|
-
} },
|
|
460
|
-
suggest(prefix) {
|
|
461
|
-
return suggestFrom(prefix, existingSuggest == null ? void 0 : () => existingSuggest(prefix));
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
const docValue = getDocValue(inner);
|
|
465
|
-
if (docValue != null) captureDocValue(wrapped, docValue);
|
|
466
|
-
if (isDerivedValueParser(inner)) preserveSuggestedDerivedMetadata(wrapped, inner, lift, includeExisting, suggestFrom);
|
|
467
|
-
return wrapped;
|
|
468
|
-
}
|
|
469
|
-
function preserveSuggestedDerivedMetadata(wrapped, parser, lift, includeExisting, suggestFrom) {
|
|
470
|
-
Object.defineProperties(wrapped, {
|
|
471
|
-
[derivedValueParserMarker]: {
|
|
472
|
-
value: true,
|
|
473
|
-
enumerable: true
|
|
474
|
-
},
|
|
475
|
-
[dependencyId]: {
|
|
476
|
-
value: parser[dependencyId],
|
|
477
|
-
enumerable: true
|
|
478
|
-
},
|
|
479
|
-
[parseWithDependency]: {
|
|
480
|
-
value(input, dependencyValue) {
|
|
481
|
-
return lift ? liftToAsync(() => parser[parseWithDependency](input, dependencyValue)) : parser[parseWithDependency](input, dependencyValue);
|
|
482
|
-
},
|
|
483
|
-
enumerable: true
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
if (dependencyIds in parser && parser[dependencyIds] != null) Object.defineProperty(wrapped, dependencyIds, {
|
|
487
|
-
value: parser[dependencyIds],
|
|
488
|
-
enumerable: true
|
|
489
|
-
});
|
|
490
|
-
if (defaultValues in parser && parser[defaultValues] != null) Object.defineProperty(wrapped, defaultValues, {
|
|
491
|
-
value: parser[defaultValues],
|
|
492
|
-
enumerable: true
|
|
493
|
-
});
|
|
494
|
-
if (singleDefaultValue in parser && parser[singleDefaultValue] != null) Object.defineProperty(wrapped, singleDefaultValue, {
|
|
495
|
-
value: parser[singleDefaultValue],
|
|
496
|
-
enumerable: true
|
|
497
|
-
});
|
|
498
|
-
if (includeExisting && suggestWithDependency in parser && parser[suggestWithDependency] != null) {
|
|
499
|
-
const existing = parser[suggestWithDependency].bind(parser);
|
|
500
|
-
Object.defineProperty(wrapped, suggestWithDependency, {
|
|
501
|
-
value(prefix, dependencyValue) {
|
|
502
|
-
return suggestFrom(prefix, () => existing(prefix, dependencyValue));
|
|
503
|
-
},
|
|
504
|
-
enumerable: true
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* Lifts a synchronous computation to async mode. It runs inside an async
|
|
510
|
-
* function, so a synchronous throw becomes a rejected promise, and the
|
|
511
|
-
* resolved result object is passed through unchanged.
|
|
512
|
-
*/
|
|
513
|
-
function liftToAsync(compute) {
|
|
514
|
-
return dispatchByMode("async", () => wrapForMode("sync", compute()), async () => await compute());
|
|
515
|
-
}
|
|
516
|
-
function isThenable(value) {
|
|
517
|
-
return isObjectLike(value) && "then" in value && typeof value.then === "function";
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Rejects results a synchronous provider must not return, even when the
|
|
521
|
-
* resulting parser is async. A thenable gets a rejection handler first so
|
|
522
|
-
* that an invalid async callback cannot cause an unhandled rejection.
|
|
523
|
-
* @throws {TypeError} If the result is not a synchronous iterable.
|
|
524
|
-
*/
|
|
525
|
-
function checkSyncProviderResult(source) {
|
|
526
|
-
if (isThenable(source)) {
|
|
527
|
-
Promise.resolve(source).then(void 0, () => {});
|
|
528
|
-
throw new TypeError("A sync suggestion provider returned a promise.");
|
|
529
|
-
}
|
|
530
|
-
return { [Symbol.iterator]: getSyncIteratorMethod(source) };
|
|
531
|
-
}
|
|
532
|
-
function isObjectLike(value) {
|
|
533
|
-
return value != null && (typeof value === "object" || typeof value === "function");
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* @throws {TypeError} If the source is not a non-string iterable.
|
|
537
|
-
*/
|
|
538
|
-
function getSyncIteratorMethod(source) {
|
|
539
|
-
if (!isObjectLike(source) || !(Symbol.iterator in source) || typeof source[Symbol.iterator] !== "function") throw new TypeError("Expected an iterable of suggestions.");
|
|
540
|
-
const iterable = source;
|
|
541
|
-
return () => iterable[Symbol.iterator]();
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* @throws {TypeError} If the source is not a non-string iterable.
|
|
545
|
-
*/
|
|
546
|
-
function getSyncIterator(source) {
|
|
547
|
-
return getSyncIteratorMethod(source)();
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* @throws {TypeError} If the source is neither an async iterable nor a
|
|
551
|
-
* non-string iterable.
|
|
552
|
-
*/
|
|
553
|
-
function getAnyIterator(source) {
|
|
554
|
-
if (isObjectLike(source) && Symbol.asyncIterator in source && typeof source[Symbol.asyncIterator] === "function") {
|
|
555
|
-
const iterable = source;
|
|
556
|
-
return iterable[Symbol.asyncIterator]();
|
|
557
|
-
}
|
|
558
|
-
return getSyncIterator(source);
|
|
559
|
-
}
|
|
560
|
-
const fileSuggestionTypes = new Set([
|
|
561
|
-
"file",
|
|
562
|
-
"directory",
|
|
563
|
-
"any"
|
|
564
|
-
]);
|
|
565
|
-
function isOptionalOfType(item, key, check) {
|
|
566
|
-
const value = Reflect.get(item, key);
|
|
567
|
-
return value === void 0 || check(value);
|
|
568
|
-
}
|
|
569
|
-
function isString(value) {
|
|
570
|
-
return typeof value === "string";
|
|
571
|
-
}
|
|
572
|
-
function isStringArray(value) {
|
|
573
|
-
return Array.isArray(value) && value.every(isString);
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
* Screens a provider item for the `Suggestion` fields that completion encoding
|
|
577
|
-
* relies on: required fields and the types of optional ones. This is shape
|
|
578
|
-
* checking, not full validation; message terms inside a description are
|
|
579
|
-
* trusted.
|
|
580
|
-
*/
|
|
581
|
-
function screenSuggestionInput(item) {
|
|
582
|
-
if (typeof item === "string") return {
|
|
583
|
-
kind: "literal",
|
|
584
|
-
text: item
|
|
585
|
-
};
|
|
586
|
-
if (item == null || typeof item !== "object" || !("kind" in item)) return void 0;
|
|
587
|
-
if (!isOptionalOfType(item, "description", Array.isArray)) return void 0;
|
|
588
|
-
if (item.kind === "literal") return "text" in item && typeof item.text === "string" ? item : void 0;
|
|
589
|
-
if (item.kind === "file") return "type" in item && fileSuggestionTypes.has(item.type) && isOptionalOfType(item, "pattern", isString) && isOptionalOfType(item, "prefix", isString) && isOptionalOfType(item, "extensions", isStringArray) && isOptionalOfType(item, "includeHidden", (value) => typeof value === "boolean") ? item : void 0;
|
|
590
|
-
return void 0;
|
|
591
|
-
}
|
|
592
|
-
function createSuggestionProcessors(prefix, filterByPrefix) {
|
|
593
|
-
const seen = /* @__PURE__ */ new Set();
|
|
594
|
-
const dedupe = (suggestion) => {
|
|
595
|
-
if (suggestion.kind !== "literal") return suggestion;
|
|
596
|
-
if (seen.has(suggestion.text)) return void 0;
|
|
597
|
-
seen.add(suggestion.text);
|
|
598
|
-
return suggestion;
|
|
599
|
-
};
|
|
600
|
-
return {
|
|
601
|
-
existing: (item) => dedupe(item),
|
|
602
|
-
provider(item) {
|
|
603
|
-
const suggestion = screenSuggestionInput(item);
|
|
604
|
-
if (suggestion == null || filterByPrefix && suggestion.kind === "literal" && !suggestion.text.startsWith(prefix)) return void 0;
|
|
605
|
-
return dedupe(suggestion);
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
function* suggestFromSources(processors, existing, provider) {
|
|
610
|
-
if (existing != null) yield* guardedSuggestions(existing, processors.existing);
|
|
611
|
-
yield* guardedSuggestions(provider, processors.provider);
|
|
612
|
-
}
|
|
613
|
-
async function* suggestFromSourcesAsync(processors, existing, provider) {
|
|
614
|
-
if (existing != null) yield* guardedSuggestionsAsync(existing, processors.existing);
|
|
615
|
-
yield* guardedSuggestionsAsync(provider, processors.provider);
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Yields processed items from one source, ending quietly on any failure.
|
|
619
|
-
* Yields happen outside the guarded regions, so consumer cancellation is never
|
|
620
|
-
* mistaken for a source failure, and the source iterator is closed when the
|
|
621
|
-
* consumer stops early.
|
|
622
|
-
*/
|
|
623
|
-
function* guardedSuggestions(getSource, process) {
|
|
624
|
-
let iterator;
|
|
625
|
-
try {
|
|
626
|
-
iterator = getSyncIterator(getSource());
|
|
627
|
-
} catch {
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
let finished = false;
|
|
631
|
-
try {
|
|
632
|
-
while (true) {
|
|
633
|
-
let suggestion;
|
|
634
|
-
try {
|
|
635
|
-
const step = iterator.next();
|
|
636
|
-
if (!isObjectLike(step)) return;
|
|
637
|
-
if (step.done) {
|
|
638
|
-
finished = true;
|
|
639
|
-
return;
|
|
640
|
-
}
|
|
641
|
-
suggestion = process(step.value);
|
|
642
|
-
} catch {
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
if (suggestion != null) yield suggestion;
|
|
646
|
-
}
|
|
647
|
-
} finally {
|
|
648
|
-
if (!finished) try {
|
|
649
|
-
iterator.return?.();
|
|
650
|
-
} catch {}
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
async function* guardedSuggestionsAsync(getSource, process) {
|
|
654
|
-
let iterator;
|
|
655
|
-
try {
|
|
656
|
-
iterator = getAnyIterator(await getSource());
|
|
657
|
-
} catch {
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
let finished = false;
|
|
661
|
-
try {
|
|
662
|
-
while (true) {
|
|
663
|
-
let suggestion;
|
|
664
|
-
try {
|
|
665
|
-
const step = await iterator.next();
|
|
666
|
-
if (!isObjectLike(step)) return;
|
|
667
|
-
if (step.done) {
|
|
668
|
-
finished = true;
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
suggestion = process(step.value);
|
|
672
|
-
} catch {
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
if (suggestion != null) yield suggestion;
|
|
676
|
-
}
|
|
677
|
-
} finally {
|
|
678
|
-
if (!finished) try {
|
|
679
|
-
await iterator.return?.();
|
|
680
|
-
} catch {}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
418
|
/**
|
|
684
419
|
* Creates a value parser that transforms the result of another value parser.
|
|
685
420
|
*
|
|
@@ -7257,4 +6992,4 @@ function plainObjectsEqual(a, b) {
|
|
|
7257
6992
|
}
|
|
7258
6993
|
|
|
7259
6994
|
//#endregion
|
|
7260
|
-
export { biject, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, locale, macAddress, normalizeInput, origin, port, portRange, regExp, semVer, socketAddress, string, transform, url, uuid
|
|
6995
|
+
export { biject, checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, locale, macAddress, normalizeInput, origin, port, portRange, regExp, semVer, socketAddress, string, transform, url, uuid };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/core",
|
|
3
|
-
"version": "1.4.0-dev.
|
|
3
|
+
"version": "1.4.0-dev.2964",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -269,7 +269,7 @@
|
|
|
269
269
|
},
|
|
270
270
|
"sideEffects": false,
|
|
271
271
|
"devDependencies": {
|
|
272
|
-
"@optique/env": "1.4.0-dev.
|
|
272
|
+
"@optique/env": "1.4.0-dev.2964+a3c24ae2",
|
|
273
273
|
"@types/node": "^24.0.0",
|
|
274
274
|
"fast-check": "^4.7.0",
|
|
275
275
|
"tsdown": "^0.13.0",
|
package/skills/optique/SKILL.md
CHANGED
|
@@ -45,9 +45,9 @@ Core rules
|
|
|
45
45
|
parsing. Use `regExp({ flags })` for user-supplied sources, `biject()` for
|
|
46
46
|
one-to-one mappings, `transform()` for mapped results, and
|
|
47
47
|
`choice(values, { key })` for custom string matching that returns the
|
|
48
|
-
declared spelling. Use `normalizeInput()`
|
|
49
|
-
`
|
|
50
|
-
|
|
48
|
+
declared spelling. Use `normalizeInput()` for raw-string cleanup and
|
|
49
|
+
`path()` from `@optique/run/valueparser` for file-system paths. Write a
|
|
50
|
+
custom value parser only when these tools do not cover the domain.
|
|
51
51
|
- Since 1.4.0, `-p8080`/`-vp8080` accept attached values. Values consume
|
|
52
52
|
the literal suffix (`-p=5` gives `"=5"`); full single-dash names win.
|
|
53
53
|
- Async value parsers like *@optique/git* make containing parsers async.
|