@optique/core 1.1.0-dev.2087 → 1.1.0-dev.2146
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/annotation-state.cjs +26 -26
- package/dist/annotation-state.d.cts +133 -1
- package/dist/annotation-state.d.ts +133 -1
- package/dist/annotations.cjs +2 -2
- package/dist/constructs.cjs +873 -73
- package/dist/constructs.d.cts +72 -1
- package/dist/constructs.d.ts +72 -1
- package/dist/constructs.js +808 -9
- package/dist/dependency-metadata.cjs +12 -12
- package/dist/dependency-metadata.d.cts +34 -3
- package/dist/dependency-metadata.d.ts +34 -3
- package/dist/dependency-runtime.cjs +37 -13
- package/dist/dependency-runtime.d.cts +197 -2
- package/dist/dependency-runtime.d.ts +197 -2
- package/dist/dependency-runtime.js +22 -1
- package/dist/dependency.cjs +7 -7
- package/dist/displaywidth.d.cts +12 -0
- package/dist/displaywidth.d.ts +12 -0
- package/dist/doc.cjs +3 -0
- package/dist/doc.js +3 -0
- package/dist/execution-context.d.cts +23 -0
- package/dist/execution-context.d.ts +23 -0
- package/dist/extension.cjs +14 -14
- package/dist/facade.cjs +49 -37
- package/dist/facade.js +34 -22
- package/dist/index.cjs +23 -21
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/input-trace.d.cts +2 -1
- package/dist/input-trace.d.ts +2 -1
- package/dist/internal/annotations.cjs +3 -0
- package/dist/internal/annotations.d.cts +47 -5
- package/dist/internal/annotations.d.ts +47 -5
- package/dist/internal/annotations.js +1 -1
- package/dist/internal/command-alias.cjs +16 -0
- package/dist/internal/command-alias.js +14 -0
- package/dist/internal/dependency.cjs +131 -0
- package/dist/internal/dependency.d.cts +311 -2
- package/dist/internal/dependency.d.ts +311 -2
- package/dist/internal/dependency.js +119 -1
- package/dist/internal/parser.cjs +108 -23
- package/dist/internal/parser.d.cts +58 -3
- package/dist/internal/parser.d.ts +58 -3
- package/dist/internal/parser.js +101 -16
- package/dist/modifiers.cjs +74 -44
- package/dist/modifiers.js +34 -4
- package/dist/parser.cjs +11 -11
- package/dist/phase2-seed.cjs +2 -2
- package/dist/phase2-seed.d.cts +50 -0
- package/dist/phase2-seed.d.ts +50 -0
- package/dist/primitives.cjs +104 -33
- package/dist/primitives.d.cts +10 -0
- package/dist/primitives.d.ts +10 -0
- package/dist/primitives.js +84 -13
- package/dist/suggestion.cjs +72 -2
- package/dist/suggestion.d.cts +188 -0
- package/dist/suggestion.d.ts +188 -0
- package/dist/suggestion.js +71 -3
- package/dist/usage-internals.cjs +14 -6
- package/dist/usage-internals.js +14 -6
- package/dist/usage.cjs +33 -8
- package/dist/usage.d.cts +31 -0
- package/dist/usage.d.ts +31 -0
- package/dist/usage.js +33 -8
- package/dist/validate.cjs +1 -0
- package/dist/validate.d.cts +99 -0
- package/dist/validate.d.ts +99 -0
- package/dist/validate.js +1 -1
- package/dist/valueparser.cjs +333 -79
- package/dist/valueparser.d.cts +197 -1
- package/dist/valueparser.d.ts +197 -1
- package/dist/valueparser.js +334 -81
- package/package.json +19 -4
package/dist/valueparser.d.cts
CHANGED
|
@@ -76,6 +76,27 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
|
|
|
76
76
|
* @since 1.0.0
|
|
77
77
|
*/
|
|
78
78
|
normalize?(value: T): T;
|
|
79
|
+
/**
|
|
80
|
+
* Validates a value of type {@link T} as if it had been parsed from CLI
|
|
81
|
+
* input, returning either a success result (with the possibly
|
|
82
|
+
* canonicalized value) or a failure with an error message.
|
|
83
|
+
*
|
|
84
|
+
* When present, `option()` and `argument()` use this method to validate
|
|
85
|
+
* fallback values (e.g. from `bindEnv()`/`bindConfig()`) instead of the
|
|
86
|
+
* generic `format()`+`parse()` round-trip. Implement it when the
|
|
87
|
+
* round-trip cannot faithfully express validation for some values, as
|
|
88
|
+
* with combinators like `firstOf()` whose constituents may produce
|
|
89
|
+
* overlapping string representations.
|
|
90
|
+
*
|
|
91
|
+
* Like {@link normalize}, this method is synchronous regardless of the
|
|
92
|
+
* parser's mode, so wrappers that spread a sync parser into an async
|
|
93
|
+
* one inherit it unchanged.
|
|
94
|
+
*
|
|
95
|
+
* @param value The value to validate.
|
|
96
|
+
* @returns A {@link ValueParserResult} indicating success or failure.
|
|
97
|
+
* @since 1.1.0
|
|
98
|
+
*/
|
|
99
|
+
validate?(value: T): ValueParserResult<T>;
|
|
79
100
|
/**
|
|
80
101
|
* Provides completion suggestions for values of this type.
|
|
81
102
|
* This is optional and used for shell completion functionality.
|
|
@@ -2711,5 +2732,180 @@ declare function json(options: JsonOptions & {
|
|
|
2711
2732
|
* @since 1.1.0
|
|
2712
2733
|
*/
|
|
2713
2734
|
declare function json(options?: JsonOptions): ValueParser<"sync", Json>;
|
|
2735
|
+
/**
|
|
2736
|
+
* Options for the {@link firstOf} combinator.
|
|
2737
|
+
* @since 1.1.0
|
|
2738
|
+
*/
|
|
2739
|
+
interface FirstOfOptions {
|
|
2740
|
+
/**
|
|
2741
|
+
* The metavariable name for the combined parser. This is used in help
|
|
2742
|
+
* messages to indicate what kind of value this parser expects.
|
|
2743
|
+
* @default The constituent metavars joined with `|`, e.g. `"TYPE|INTEGER"`.
|
|
2744
|
+
*/
|
|
2745
|
+
readonly metavar?: NonEmptyString;
|
|
2746
|
+
/**
|
|
2747
|
+
* Custom error messages for firstOf parsing failures.
|
|
2748
|
+
* @since 1.1.0
|
|
2749
|
+
*/
|
|
2750
|
+
readonly errors?: {
|
|
2751
|
+
/**
|
|
2752
|
+
* Custom error message when every constituent parser fails. Can be a
|
|
2753
|
+
* static message or a function that receives the input and the
|
|
2754
|
+
* constituent errors in declaration order.
|
|
2755
|
+
* @since 1.1.0
|
|
2756
|
+
*/
|
|
2757
|
+
readonly noMatch?: Message | ((input: string, errors: readonly Message[]) => Message);
|
|
2758
|
+
};
|
|
2759
|
+
}
|
|
2760
|
+
/**
|
|
2761
|
+
* The trailing options argument of {@link firstOf}. A {@link ValueParser}
|
|
2762
|
+
* structurally satisfies {@link FirstOfOptions} (its `metavar` field matches
|
|
2763
|
+
* the optional one), so the required `parse` method is excluded to keep
|
|
2764
|
+
* the overloads unambiguous.
|
|
2765
|
+
*/
|
|
2766
|
+
type FirstOfTailOptions = FirstOfOptions & {
|
|
2767
|
+
readonly parse?: never;
|
|
2768
|
+
};
|
|
2769
|
+
/**
|
|
2770
|
+
* Extracts the result type of a sync {@link ValueParser}.
|
|
2771
|
+
*/
|
|
2772
|
+
type ValueParserValue<P> = P extends ValueParser<"sync", infer T> ? T : never;
|
|
2773
|
+
/**
|
|
2774
|
+
* Creates a {@link ValueParser} that tries two value parsers in declaration
|
|
2775
|
+
* order and returns the result of the first one that succeeds.
|
|
2776
|
+
*
|
|
2777
|
+
* The result type is the union of the constituent result types:
|
|
2778
|
+
*
|
|
2779
|
+
* ```typescript
|
|
2780
|
+
* const count = firstOf(choice(["auto"]), integer({ min: 1 }));
|
|
2781
|
+
* // Inferred type: ValueParser<"sync", "auto" | number>
|
|
2782
|
+
* ```
|
|
2783
|
+
*
|
|
2784
|
+
* When every constituent fails, the combined error lists each constituent's
|
|
2785
|
+
* error on its own line.
|
|
2786
|
+
* @template TA The result type of the first parser.
|
|
2787
|
+
* @template TB The result type of the second parser.
|
|
2788
|
+
* @param a The first value parser to try.
|
|
2789
|
+
* @param b The second value parser to try.
|
|
2790
|
+
* @param options Configuration options for the combined parser.
|
|
2791
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2792
|
+
* constituent parsers.
|
|
2793
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2794
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2795
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2796
|
+
* @since 1.1.0
|
|
2797
|
+
*/
|
|
2798
|
+
declare function firstOf<TA, TB>(a: ValueParser<"sync", TA>, b: ValueParser<"sync", TB>, options?: FirstOfTailOptions): ValueParser<"sync", TA | TB>;
|
|
2799
|
+
/**
|
|
2800
|
+
* Creates a {@link ValueParser} that tries three value parsers in declaration
|
|
2801
|
+
* order and returns the result of the first one that succeeds.
|
|
2802
|
+
* @template TA The result type of the first parser.
|
|
2803
|
+
* @template TB The result type of the second parser.
|
|
2804
|
+
* @template TC The result type of the third parser.
|
|
2805
|
+
* @param a The first value parser to try.
|
|
2806
|
+
* @param b The second value parser to try.
|
|
2807
|
+
* @param c The third value parser to try.
|
|
2808
|
+
* @param options Configuration options for the combined parser.
|
|
2809
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2810
|
+
* constituent parsers.
|
|
2811
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2812
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2813
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2814
|
+
* @since 1.1.0
|
|
2815
|
+
*/
|
|
2816
|
+
declare function firstOf<TA, TB, TC>(a: ValueParser<"sync", TA>, b: ValueParser<"sync", TB>, c: ValueParser<"sync", TC>, options?: FirstOfTailOptions): ValueParser<"sync", TA | TB | TC>;
|
|
2817
|
+
/**
|
|
2818
|
+
* Creates a {@link ValueParser} that tries four value parsers in declaration
|
|
2819
|
+
* order and returns the result of the first one that succeeds.
|
|
2820
|
+
* @template TA The result type of the first parser.
|
|
2821
|
+
* @template TB The result type of the second parser.
|
|
2822
|
+
* @template TC The result type of the third parser.
|
|
2823
|
+
* @template TD The result type of the fourth parser.
|
|
2824
|
+
* @param a The first value parser to try.
|
|
2825
|
+
* @param b The second value parser to try.
|
|
2826
|
+
* @param c The third value parser to try.
|
|
2827
|
+
* @param d The fourth value parser to try.
|
|
2828
|
+
* @param options Configuration options for the combined parser.
|
|
2829
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2830
|
+
* constituent parsers.
|
|
2831
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2832
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2833
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2834
|
+
* @since 1.1.0
|
|
2835
|
+
*/
|
|
2836
|
+
declare function firstOf<TA, TB, TC, TD>(a: ValueParser<"sync", TA>, b: ValueParser<"sync", TB>, c: ValueParser<"sync", TC>, d: ValueParser<"sync", TD>, options?: FirstOfTailOptions): ValueParser<"sync", TA | TB | TC | TD>;
|
|
2837
|
+
/**
|
|
2838
|
+
* Creates a {@link ValueParser} that tries five value parsers in declaration
|
|
2839
|
+
* order and returns the result of the first one that succeeds.
|
|
2840
|
+
* @template TA The result type of the first parser.
|
|
2841
|
+
* @template TB The result type of the second parser.
|
|
2842
|
+
* @template TC The result type of the third parser.
|
|
2843
|
+
* @template TD The result type of the fourth parser.
|
|
2844
|
+
* @template TE The result type of the fifth parser.
|
|
2845
|
+
* @param a The first value parser to try.
|
|
2846
|
+
* @param b The second value parser to try.
|
|
2847
|
+
* @param c The third value parser to try.
|
|
2848
|
+
* @param d The fourth value parser to try.
|
|
2849
|
+
* @param e The fifth value parser to try.
|
|
2850
|
+
* @param options Configuration options for the combined parser.
|
|
2851
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2852
|
+
* constituent parsers.
|
|
2853
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2854
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2855
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2856
|
+
* @since 1.1.0
|
|
2857
|
+
*/
|
|
2858
|
+
declare function firstOf<TA, TB, TC, TD, TE>(a: ValueParser<"sync", TA>, b: ValueParser<"sync", TB>, c: ValueParser<"sync", TC>, d: ValueParser<"sync", TD>, e: ValueParser<"sync", TE>, options?: FirstOfTailOptions): ValueParser<"sync", TA | TB | TC | TD | TE>;
|
|
2859
|
+
/**
|
|
2860
|
+
* Creates a {@link ValueParser} that tries any number of value parsers in
|
|
2861
|
+
* declaration order and returns the result of the first one that succeeds.
|
|
2862
|
+
* @template TParsers The tuple of constituent value parsers.
|
|
2863
|
+
* @param args The value parsers to try, followed by configuration options.
|
|
2864
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2865
|
+
* constituent parsers.
|
|
2866
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2867
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2868
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2869
|
+
* @since 1.1.0
|
|
2870
|
+
*/
|
|
2871
|
+
declare function firstOf<const TParsers extends readonly [ValueParser<"sync", unknown>, ValueParser<"sync", unknown>, ...ValueParser<"sync", unknown>[]]>(...args: [...parsers: TParsers, options: FirstOfTailOptions]): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
2872
|
+
/**
|
|
2873
|
+
* Creates a {@link ValueParser} that tries any number of value parsers in
|
|
2874
|
+
* declaration order and returns the result of the first one that succeeds.
|
|
2875
|
+
* @template TParsers The tuple of constituent value parsers.
|
|
2876
|
+
* @param parsers The value parsers to try.
|
|
2877
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2878
|
+
* constituent parsers.
|
|
2879
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2880
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2881
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2882
|
+
* @since 1.1.0
|
|
2883
|
+
*/
|
|
2884
|
+
declare function firstOf<const TParsers extends readonly [ValueParser<"sync", unknown>, ValueParser<"sync", unknown>, ...ValueParser<"sync", unknown>[]]>(...parsers: TParsers): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
2885
|
+
/**
|
|
2886
|
+
* Creates a {@link ValueParser} that tries the value parsers in the given
|
|
2887
|
+
* array in declaration order and returns the result of the first one that
|
|
2888
|
+
* succeeds.
|
|
2889
|
+
*
|
|
2890
|
+
* Unlike the variadic overloads, which require at least two statically
|
|
2891
|
+
* known arguments, this form accepts a dynamically built array:
|
|
2892
|
+
*
|
|
2893
|
+
* ```typescript
|
|
2894
|
+
* const parsers: ValueParser<"sync", string | number>[] = buildParsers();
|
|
2895
|
+
* const combined = firstOf(parsers);
|
|
2896
|
+
* ```
|
|
2897
|
+
* @template TParsers The array of constituent value parsers.
|
|
2898
|
+
* @param parsers The value parsers to try. Must contain at least two
|
|
2899
|
+
* parsers.
|
|
2900
|
+
* @param options Configuration options for the combined parser.
|
|
2901
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2902
|
+
* constituent parsers.
|
|
2903
|
+
* @throws {TypeError} If the array contains fewer than two value parsers.
|
|
2904
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2905
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2906
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2907
|
+
* @since 1.1.0
|
|
2908
|
+
*/
|
|
2909
|
+
declare function firstOf<const TParsers extends readonly ValueParser<"sync", unknown>[]>(parsers: TParsers, options?: FirstOfOptions): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
2714
2910
|
//#endregion
|
|
2715
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|
|
2911
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -76,6 +76,27 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
|
|
|
76
76
|
* @since 1.0.0
|
|
77
77
|
*/
|
|
78
78
|
normalize?(value: T): T;
|
|
79
|
+
/**
|
|
80
|
+
* Validates a value of type {@link T} as if it had been parsed from CLI
|
|
81
|
+
* input, returning either a success result (with the possibly
|
|
82
|
+
* canonicalized value) or a failure with an error message.
|
|
83
|
+
*
|
|
84
|
+
* When present, `option()` and `argument()` use this method to validate
|
|
85
|
+
* fallback values (e.g. from `bindEnv()`/`bindConfig()`) instead of the
|
|
86
|
+
* generic `format()`+`parse()` round-trip. Implement it when the
|
|
87
|
+
* round-trip cannot faithfully express validation for some values, as
|
|
88
|
+
* with combinators like `firstOf()` whose constituents may produce
|
|
89
|
+
* overlapping string representations.
|
|
90
|
+
*
|
|
91
|
+
* Like {@link normalize}, this method is synchronous regardless of the
|
|
92
|
+
* parser's mode, so wrappers that spread a sync parser into an async
|
|
93
|
+
* one inherit it unchanged.
|
|
94
|
+
*
|
|
95
|
+
* @param value The value to validate.
|
|
96
|
+
* @returns A {@link ValueParserResult} indicating success or failure.
|
|
97
|
+
* @since 1.1.0
|
|
98
|
+
*/
|
|
99
|
+
validate?(value: T): ValueParserResult<T>;
|
|
79
100
|
/**
|
|
80
101
|
* Provides completion suggestions for values of this type.
|
|
81
102
|
* This is optional and used for shell completion functionality.
|
|
@@ -2711,5 +2732,180 @@ declare function json(options: JsonOptions & {
|
|
|
2711
2732
|
* @since 1.1.0
|
|
2712
2733
|
*/
|
|
2713
2734
|
declare function json(options?: JsonOptions): ValueParser<"sync", Json>;
|
|
2735
|
+
/**
|
|
2736
|
+
* Options for the {@link firstOf} combinator.
|
|
2737
|
+
* @since 1.1.0
|
|
2738
|
+
*/
|
|
2739
|
+
interface FirstOfOptions {
|
|
2740
|
+
/**
|
|
2741
|
+
* The metavariable name for the combined parser. This is used in help
|
|
2742
|
+
* messages to indicate what kind of value this parser expects.
|
|
2743
|
+
* @default The constituent metavars joined with `|`, e.g. `"TYPE|INTEGER"`.
|
|
2744
|
+
*/
|
|
2745
|
+
readonly metavar?: NonEmptyString;
|
|
2746
|
+
/**
|
|
2747
|
+
* Custom error messages for firstOf parsing failures.
|
|
2748
|
+
* @since 1.1.0
|
|
2749
|
+
*/
|
|
2750
|
+
readonly errors?: {
|
|
2751
|
+
/**
|
|
2752
|
+
* Custom error message when every constituent parser fails. Can be a
|
|
2753
|
+
* static message or a function that receives the input and the
|
|
2754
|
+
* constituent errors in declaration order.
|
|
2755
|
+
* @since 1.1.0
|
|
2756
|
+
*/
|
|
2757
|
+
readonly noMatch?: Message | ((input: string, errors: readonly Message[]) => Message);
|
|
2758
|
+
};
|
|
2759
|
+
}
|
|
2760
|
+
/**
|
|
2761
|
+
* The trailing options argument of {@link firstOf}. A {@link ValueParser}
|
|
2762
|
+
* structurally satisfies {@link FirstOfOptions} (its `metavar` field matches
|
|
2763
|
+
* the optional one), so the required `parse` method is excluded to keep
|
|
2764
|
+
* the overloads unambiguous.
|
|
2765
|
+
*/
|
|
2766
|
+
type FirstOfTailOptions = FirstOfOptions & {
|
|
2767
|
+
readonly parse?: never;
|
|
2768
|
+
};
|
|
2769
|
+
/**
|
|
2770
|
+
* Extracts the result type of a sync {@link ValueParser}.
|
|
2771
|
+
*/
|
|
2772
|
+
type ValueParserValue<P> = P extends ValueParser<"sync", infer T> ? T : never;
|
|
2773
|
+
/**
|
|
2774
|
+
* Creates a {@link ValueParser} that tries two value parsers in declaration
|
|
2775
|
+
* order and returns the result of the first one that succeeds.
|
|
2776
|
+
*
|
|
2777
|
+
* The result type is the union of the constituent result types:
|
|
2778
|
+
*
|
|
2779
|
+
* ```typescript
|
|
2780
|
+
* const count = firstOf(choice(["auto"]), integer({ min: 1 }));
|
|
2781
|
+
* // Inferred type: ValueParser<"sync", "auto" | number>
|
|
2782
|
+
* ```
|
|
2783
|
+
*
|
|
2784
|
+
* When every constituent fails, the combined error lists each constituent's
|
|
2785
|
+
* error on its own line.
|
|
2786
|
+
* @template TA The result type of the first parser.
|
|
2787
|
+
* @template TB The result type of the second parser.
|
|
2788
|
+
* @param a The first value parser to try.
|
|
2789
|
+
* @param b The second value parser to try.
|
|
2790
|
+
* @param options Configuration options for the combined parser.
|
|
2791
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2792
|
+
* constituent parsers.
|
|
2793
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2794
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2795
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2796
|
+
* @since 1.1.0
|
|
2797
|
+
*/
|
|
2798
|
+
declare function firstOf<TA, TB>(a: ValueParser<"sync", TA>, b: ValueParser<"sync", TB>, options?: FirstOfTailOptions): ValueParser<"sync", TA | TB>;
|
|
2799
|
+
/**
|
|
2800
|
+
* Creates a {@link ValueParser} that tries three value parsers in declaration
|
|
2801
|
+
* order and returns the result of the first one that succeeds.
|
|
2802
|
+
* @template TA The result type of the first parser.
|
|
2803
|
+
* @template TB The result type of the second parser.
|
|
2804
|
+
* @template TC The result type of the third parser.
|
|
2805
|
+
* @param a The first value parser to try.
|
|
2806
|
+
* @param b The second value parser to try.
|
|
2807
|
+
* @param c The third value parser to try.
|
|
2808
|
+
* @param options Configuration options for the combined parser.
|
|
2809
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2810
|
+
* constituent parsers.
|
|
2811
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2812
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2813
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2814
|
+
* @since 1.1.0
|
|
2815
|
+
*/
|
|
2816
|
+
declare function firstOf<TA, TB, TC>(a: ValueParser<"sync", TA>, b: ValueParser<"sync", TB>, c: ValueParser<"sync", TC>, options?: FirstOfTailOptions): ValueParser<"sync", TA | TB | TC>;
|
|
2817
|
+
/**
|
|
2818
|
+
* Creates a {@link ValueParser} that tries four value parsers in declaration
|
|
2819
|
+
* order and returns the result of the first one that succeeds.
|
|
2820
|
+
* @template TA The result type of the first parser.
|
|
2821
|
+
* @template TB The result type of the second parser.
|
|
2822
|
+
* @template TC The result type of the third parser.
|
|
2823
|
+
* @template TD The result type of the fourth parser.
|
|
2824
|
+
* @param a The first value parser to try.
|
|
2825
|
+
* @param b The second value parser to try.
|
|
2826
|
+
* @param c The third value parser to try.
|
|
2827
|
+
* @param d The fourth value parser to try.
|
|
2828
|
+
* @param options Configuration options for the combined parser.
|
|
2829
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2830
|
+
* constituent parsers.
|
|
2831
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2832
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2833
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2834
|
+
* @since 1.1.0
|
|
2835
|
+
*/
|
|
2836
|
+
declare function firstOf<TA, TB, TC, TD>(a: ValueParser<"sync", TA>, b: ValueParser<"sync", TB>, c: ValueParser<"sync", TC>, d: ValueParser<"sync", TD>, options?: FirstOfTailOptions): ValueParser<"sync", TA | TB | TC | TD>;
|
|
2837
|
+
/**
|
|
2838
|
+
* Creates a {@link ValueParser} that tries five value parsers in declaration
|
|
2839
|
+
* order and returns the result of the first one that succeeds.
|
|
2840
|
+
* @template TA The result type of the first parser.
|
|
2841
|
+
* @template TB The result type of the second parser.
|
|
2842
|
+
* @template TC The result type of the third parser.
|
|
2843
|
+
* @template TD The result type of the fourth parser.
|
|
2844
|
+
* @template TE The result type of the fifth parser.
|
|
2845
|
+
* @param a The first value parser to try.
|
|
2846
|
+
* @param b The second value parser to try.
|
|
2847
|
+
* @param c The third value parser to try.
|
|
2848
|
+
* @param d The fourth value parser to try.
|
|
2849
|
+
* @param e The fifth value parser to try.
|
|
2850
|
+
* @param options Configuration options for the combined parser.
|
|
2851
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2852
|
+
* constituent parsers.
|
|
2853
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2854
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2855
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2856
|
+
* @since 1.1.0
|
|
2857
|
+
*/
|
|
2858
|
+
declare function firstOf<TA, TB, TC, TD, TE>(a: ValueParser<"sync", TA>, b: ValueParser<"sync", TB>, c: ValueParser<"sync", TC>, d: ValueParser<"sync", TD>, e: ValueParser<"sync", TE>, options?: FirstOfTailOptions): ValueParser<"sync", TA | TB | TC | TD | TE>;
|
|
2859
|
+
/**
|
|
2860
|
+
* Creates a {@link ValueParser} that tries any number of value parsers in
|
|
2861
|
+
* declaration order and returns the result of the first one that succeeds.
|
|
2862
|
+
* @template TParsers The tuple of constituent value parsers.
|
|
2863
|
+
* @param args The value parsers to try, followed by configuration options.
|
|
2864
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2865
|
+
* constituent parsers.
|
|
2866
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2867
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2868
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2869
|
+
* @since 1.1.0
|
|
2870
|
+
*/
|
|
2871
|
+
declare function firstOf<const TParsers extends readonly [ValueParser<"sync", unknown>, ValueParser<"sync", unknown>, ...ValueParser<"sync", unknown>[]]>(...args: [...parsers: TParsers, options: FirstOfTailOptions]): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
2872
|
+
/**
|
|
2873
|
+
* Creates a {@link ValueParser} that tries any number of value parsers in
|
|
2874
|
+
* declaration order and returns the result of the first one that succeeds.
|
|
2875
|
+
* @template TParsers The tuple of constituent value parsers.
|
|
2876
|
+
* @param parsers The value parsers to try.
|
|
2877
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2878
|
+
* constituent parsers.
|
|
2879
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2880
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2881
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2882
|
+
* @since 1.1.0
|
|
2883
|
+
*/
|
|
2884
|
+
declare function firstOf<const TParsers extends readonly [ValueParser<"sync", unknown>, ValueParser<"sync", unknown>, ...ValueParser<"sync", unknown>[]]>(...parsers: TParsers): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
2885
|
+
/**
|
|
2886
|
+
* Creates a {@link ValueParser} that tries the value parsers in the given
|
|
2887
|
+
* array in declaration order and returns the result of the first one that
|
|
2888
|
+
* succeeds.
|
|
2889
|
+
*
|
|
2890
|
+
* Unlike the variadic overloads, which require at least two statically
|
|
2891
|
+
* known arguments, this form accepts a dynamically built array:
|
|
2892
|
+
*
|
|
2893
|
+
* ```typescript
|
|
2894
|
+
* const parsers: ValueParser<"sync", string | number>[] = buildParsers();
|
|
2895
|
+
* const combined = firstOf(parsers);
|
|
2896
|
+
* ```
|
|
2897
|
+
* @template TParsers The array of constituent value parsers.
|
|
2898
|
+
* @param parsers The value parsers to try. Must contain at least two
|
|
2899
|
+
* parsers.
|
|
2900
|
+
* @param options Configuration options for the combined parser.
|
|
2901
|
+
* @returns A {@link ValueParser} that accepts values matching any of the
|
|
2902
|
+
* constituent parsers.
|
|
2903
|
+
* @throws {TypeError} If the array contains fewer than two value parsers.
|
|
2904
|
+
* @throws {TypeError} If any constituent is not a sync value parser.
|
|
2905
|
+
* @throws {TypeError} If any constituent is a dependency-derived value
|
|
2906
|
+
* parser (created via `deriveFrom()` or `dependency().derive()`).
|
|
2907
|
+
* @since 1.1.0
|
|
2908
|
+
*/
|
|
2909
|
+
declare function firstOf<const TParsers extends readonly ValueParser<"sync", unknown>[]>(parsers: TParsers, options?: FirstOfOptions): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
2714
2910
|
//#endregion
|
|
2715
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|
|
2911
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|