@optique/core 1.1.0-dev.2148 → 1.1.0-dev.2160

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.
@@ -385,6 +385,130 @@ declare function checkEnumOption<T extends object>(options: T | undefined, key:
385
385
  * `RegExp` instance.
386
386
  */
387
387
  declare function string(options?: StringOptions): ValueParser<"sync", string>;
388
+ interface KeyValueOptionsBase {
389
+ /**
390
+ * The metavariable name for this parser. Used in help messages to
391
+ * indicate the expected key–value shape.
392
+ * @default `"KEY=VALUE"` with the configured separator.
393
+ */
394
+ readonly metavar?: NonEmptyString;
395
+ /**
396
+ * The separator between key and value.
397
+ * @default `"="`
398
+ */
399
+ readonly separator?: string;
400
+ /**
401
+ * If `true`, accepts an empty key before the separator.
402
+ * @default `false`
403
+ */
404
+ readonly allowEmptyKey?: boolean;
405
+ /**
406
+ * If `true`, accepts an empty value after the separator.
407
+ * @default `true`
408
+ */
409
+ readonly allowEmptyValue?: boolean;
410
+ /**
411
+ * Chooses which separator occurrence is used when input contains the
412
+ * separator more than once.
413
+ * @default `"first"`
414
+ */
415
+ readonly split?: "first" | "last";
416
+ /**
417
+ * Custom error messages for key–value parsing failures.
418
+ * @since 1.1.0
419
+ */
420
+ readonly errors?: {
421
+ /**
422
+ * Custom error when the input does not contain the separator.
423
+ */
424
+ readonly missingSeparator?: Message | ((input: string, separator: string) => Message);
425
+ /**
426
+ * Custom error when the key side is empty and empty keys are disabled.
427
+ */
428
+ readonly emptyKey?: Message | ((input: string) => Message);
429
+ /**
430
+ * Custom error when the value side is empty and empty values are disabled.
431
+ */
432
+ readonly emptyValue?: Message | ((input: string) => Message);
433
+ /**
434
+ * Custom error wrapper for key parser failures.
435
+ */
436
+ readonly invalidKey?: Message | ((error: Message) => Message);
437
+ /**
438
+ * Custom error wrapper for value parser failures.
439
+ */
440
+ readonly invalidValue?: Message | ((error: Message) => Message);
441
+ };
442
+ }
443
+ type IsDefaultString<T> = [T] extends [string] ? [string] extends [T] ? true : false : false;
444
+ type KeyValueKeyOption<K> = IsDefaultString<K> extends true ? {
445
+ /**
446
+ * Parser used to validate and transform the key side.
447
+ * @default `string({ placeholder: "KEY" })`
448
+ */
449
+ readonly key?: ValueParser<"sync", K>;
450
+ } : {
451
+ /**
452
+ * Parser used to validate and transform the key side.
453
+ * @default `string({ placeholder: "KEY" })`
454
+ */
455
+ readonly key: ValueParser<"sync", K>;
456
+ };
457
+ type KeyValueValueOption<V> = IsDefaultString<V> extends true ? {
458
+ /**
459
+ * Parser used to validate and transform the value side.
460
+ * @default `string()`
461
+ */
462
+ readonly value?: ValueParser<"sync", V>;
463
+ } : {
464
+ /**
465
+ * Parser used to validate and transform the value side.
466
+ * @default `string()`
467
+ */
468
+ readonly value: ValueParser<"sync", V>;
469
+ };
470
+ /**
471
+ * Options for creating a {@link keyValue} parser.
472
+ *
473
+ * The default key and value parsers produce strings. If {@link K} or
474
+ * {@link V} is anything other than the default `string` type, the
475
+ * corresponding child parser is required so the option object cannot promise
476
+ * a type that the default parser would not produce.
477
+ *
478
+ * @template K The parsed key type.
479
+ * @template V The parsed value type.
480
+ * @since 1.1.0
481
+ */
482
+ type KeyValueOptions<K = string, V = string> = KeyValueOptionsBase & KeyValueKeyOption<K> & KeyValueValueOption<V>;
483
+ type KeyValueOptionsInput = KeyValueOptionsBase & {
484
+ readonly key?: ValueParser<"sync", unknown>;
485
+ readonly value?: ValueParser<"sync", unknown>;
486
+ };
487
+ type KeyValueKeyType<Options> = Options extends {
488
+ readonly key: ValueParser<"sync", infer K>;
489
+ } ? K : string;
490
+ type KeyValueValueType<Options> = Options extends {
491
+ readonly value: ValueParser<"sync", infer V>;
492
+ } ? V : string;
493
+ type KeyValueResultType<Options> = Options extends KeyValueOptionsInput ? readonly [KeyValueKeyType<Options>, KeyValueValueType<Options>] : readonly [string, string];
494
+ /**
495
+ * Creates a value parser for strings shaped like `KEY=VALUE`.
496
+ *
497
+ * The default parser splits on the first `=`, rejects empty keys, allows
498
+ * empty values, and returns a readonly `[key, value]` tuple. Custom key and
499
+ * value parsers can narrow or transform either side while preserving the
500
+ * inferred tuple type.
501
+ *
502
+ * @template Options The option object type used to infer child parser results.
503
+ * @param options Configuration options for the key–value parser.
504
+ * @returns A sync value parser producing readonly key–value tuples.
505
+ * @throws {TypeError} If `separator` or `metavar` is empty, if
506
+ * `allowEmptyKey` or `allowEmptyValue` is not a boolean, if `split` is not
507
+ * `"first"` or `"last"`, or if `key` or `value` is not a sync value parser.
508
+ * @since 1.1.0
509
+ */
510
+ declare function keyValue(): ValueParser<"sync", readonly [string, string]>;
511
+ declare function keyValue<const Options extends KeyValueOptionsInput | undefined>(options: Options): ValueParser<"sync", KeyValueResultType<Options>>;
388
512
  /**
389
513
  * Options for creating an integer parser that returns a JavaScript `number`.
390
514
  *
@@ -1572,10 +1696,34 @@ interface SocketAddressOptions {
1572
1696
  */
1573
1697
  readonly hostname?: Omit<HostnameOptions, "metavar" | "errors">;
1574
1698
  /**
1575
- * Options for IP validation (when type is "ip" or "both").
1576
- * Currently only supports IPv4.
1699
+ * IP version to accept when `type` is `"ip"` or `"both"`.
1700
+ * - `4`: IPv4 only
1701
+ * - `6`: IPv6 only
1702
+ * - `"both"`: Accept both IPv4 and IPv6
1703
+ *
1704
+ * @default `"both"` unless only the legacy {@link ip} field is set, in
1705
+ * which case the default is `4` to preserve IPv4-only compatibility.
1706
+ * @since 1.1.0
1707
+ */
1708
+ readonly version?: 4 | 6 | "both";
1709
+ /**
1710
+ * Options for IPv4 validation (when type is "ip" or "both").
1711
+ * This is kept for backwards compatibility; prefer {@link ipv4} for
1712
+ * new code.
1577
1713
  */
1578
1714
  readonly ip?: Omit<Ipv4Options, "metavar" | "errors">;
1715
+ /**
1716
+ * Options for IPv4 validation (when type is "ip" or "both").
1717
+ *
1718
+ * @since 1.1.0
1719
+ */
1720
+ readonly ipv4?: Omit<Ipv4Options, "metavar" | "errors">;
1721
+ /**
1722
+ * Options for IPv6 validation (when type is "ip" or "both").
1723
+ *
1724
+ * @since 1.1.0
1725
+ */
1726
+ readonly ipv6?: Omit<Ipv6Options, "metavar" | "errors">;
1579
1727
  };
1580
1728
  /**
1581
1729
  * Options for port validation.
@@ -1601,7 +1749,7 @@ interface SocketAddressOptions {
1601
1749
  * Creates a value parser for socket addresses in "host:port" format.
1602
1750
  *
1603
1751
  * Validates socket addresses with support for:
1604
- * - Hostnames and IPv4 addresses (IPv6 support coming in future versions)
1752
+ * - Hostnames, IPv4 addresses, and IPv6 addresses
1605
1753
  * - Configurable host:port separator
1606
1754
  * - Optional default port
1607
1755
  * - Host type filtering (hostname only, IP only, or both)
@@ -1612,6 +1760,8 @@ interface SocketAddressOptions {
1612
1760
  * @throws {TypeError} If `separator` is an empty string.
1613
1761
  * @throws {TypeError} If `separator` contains digit characters, since digits
1614
1762
  * in the separator would cause ambiguous splitting of port input.
1763
+ * @throws {TypeError} If `host.version` is provided but is not `4`, `6`, or
1764
+ * `"both"`.
1615
1765
  * @since 0.10.0
1616
1766
  *
1617
1767
  * @example
@@ -2908,4 +3058,4 @@ declare function firstOf<const TParsers extends readonly [ValueParser<"sync", un
2908
3058
  */
2909
3059
  declare function firstOf<const TParsers extends readonly ValueParser<"sync", unknown>[]>(parsers: TParsers, options?: FirstOfOptions): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
2910
3060
  //#endregion
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 };
3061
+ 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, KeyValueOptions, 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, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
@@ -385,6 +385,130 @@ declare function checkEnumOption<T extends object>(options: T | undefined, key:
385
385
  * `RegExp` instance.
386
386
  */
387
387
  declare function string(options?: StringOptions): ValueParser<"sync", string>;
388
+ interface KeyValueOptionsBase {
389
+ /**
390
+ * The metavariable name for this parser. Used in help messages to
391
+ * indicate the expected key–value shape.
392
+ * @default `"KEY=VALUE"` with the configured separator.
393
+ */
394
+ readonly metavar?: NonEmptyString;
395
+ /**
396
+ * The separator between key and value.
397
+ * @default `"="`
398
+ */
399
+ readonly separator?: string;
400
+ /**
401
+ * If `true`, accepts an empty key before the separator.
402
+ * @default `false`
403
+ */
404
+ readonly allowEmptyKey?: boolean;
405
+ /**
406
+ * If `true`, accepts an empty value after the separator.
407
+ * @default `true`
408
+ */
409
+ readonly allowEmptyValue?: boolean;
410
+ /**
411
+ * Chooses which separator occurrence is used when input contains the
412
+ * separator more than once.
413
+ * @default `"first"`
414
+ */
415
+ readonly split?: "first" | "last";
416
+ /**
417
+ * Custom error messages for key–value parsing failures.
418
+ * @since 1.1.0
419
+ */
420
+ readonly errors?: {
421
+ /**
422
+ * Custom error when the input does not contain the separator.
423
+ */
424
+ readonly missingSeparator?: Message | ((input: string, separator: string) => Message);
425
+ /**
426
+ * Custom error when the key side is empty and empty keys are disabled.
427
+ */
428
+ readonly emptyKey?: Message | ((input: string) => Message);
429
+ /**
430
+ * Custom error when the value side is empty and empty values are disabled.
431
+ */
432
+ readonly emptyValue?: Message | ((input: string) => Message);
433
+ /**
434
+ * Custom error wrapper for key parser failures.
435
+ */
436
+ readonly invalidKey?: Message | ((error: Message) => Message);
437
+ /**
438
+ * Custom error wrapper for value parser failures.
439
+ */
440
+ readonly invalidValue?: Message | ((error: Message) => Message);
441
+ };
442
+ }
443
+ type IsDefaultString<T> = [T] extends [string] ? [string] extends [T] ? true : false : false;
444
+ type KeyValueKeyOption<K> = IsDefaultString<K> extends true ? {
445
+ /**
446
+ * Parser used to validate and transform the key side.
447
+ * @default `string({ placeholder: "KEY" })`
448
+ */
449
+ readonly key?: ValueParser<"sync", K>;
450
+ } : {
451
+ /**
452
+ * Parser used to validate and transform the key side.
453
+ * @default `string({ placeholder: "KEY" })`
454
+ */
455
+ readonly key: ValueParser<"sync", K>;
456
+ };
457
+ type KeyValueValueOption<V> = IsDefaultString<V> extends true ? {
458
+ /**
459
+ * Parser used to validate and transform the value side.
460
+ * @default `string()`
461
+ */
462
+ readonly value?: ValueParser<"sync", V>;
463
+ } : {
464
+ /**
465
+ * Parser used to validate and transform the value side.
466
+ * @default `string()`
467
+ */
468
+ readonly value: ValueParser<"sync", V>;
469
+ };
470
+ /**
471
+ * Options for creating a {@link keyValue} parser.
472
+ *
473
+ * The default key and value parsers produce strings. If {@link K} or
474
+ * {@link V} is anything other than the default `string` type, the
475
+ * corresponding child parser is required so the option object cannot promise
476
+ * a type that the default parser would not produce.
477
+ *
478
+ * @template K The parsed key type.
479
+ * @template V The parsed value type.
480
+ * @since 1.1.0
481
+ */
482
+ type KeyValueOptions<K = string, V = string> = KeyValueOptionsBase & KeyValueKeyOption<K> & KeyValueValueOption<V>;
483
+ type KeyValueOptionsInput = KeyValueOptionsBase & {
484
+ readonly key?: ValueParser<"sync", unknown>;
485
+ readonly value?: ValueParser<"sync", unknown>;
486
+ };
487
+ type KeyValueKeyType<Options> = Options extends {
488
+ readonly key: ValueParser<"sync", infer K>;
489
+ } ? K : string;
490
+ type KeyValueValueType<Options> = Options extends {
491
+ readonly value: ValueParser<"sync", infer V>;
492
+ } ? V : string;
493
+ type KeyValueResultType<Options> = Options extends KeyValueOptionsInput ? readonly [KeyValueKeyType<Options>, KeyValueValueType<Options>] : readonly [string, string];
494
+ /**
495
+ * Creates a value parser for strings shaped like `KEY=VALUE`.
496
+ *
497
+ * The default parser splits on the first `=`, rejects empty keys, allows
498
+ * empty values, and returns a readonly `[key, value]` tuple. Custom key and
499
+ * value parsers can narrow or transform either side while preserving the
500
+ * inferred tuple type.
501
+ *
502
+ * @template Options The option object type used to infer child parser results.
503
+ * @param options Configuration options for the key–value parser.
504
+ * @returns A sync value parser producing readonly key–value tuples.
505
+ * @throws {TypeError} If `separator` or `metavar` is empty, if
506
+ * `allowEmptyKey` or `allowEmptyValue` is not a boolean, if `split` is not
507
+ * `"first"` or `"last"`, or if `key` or `value` is not a sync value parser.
508
+ * @since 1.1.0
509
+ */
510
+ declare function keyValue(): ValueParser<"sync", readonly [string, string]>;
511
+ declare function keyValue<const Options extends KeyValueOptionsInput | undefined>(options: Options): ValueParser<"sync", KeyValueResultType<Options>>;
388
512
  /**
389
513
  * Options for creating an integer parser that returns a JavaScript `number`.
390
514
  *
@@ -1572,10 +1696,34 @@ interface SocketAddressOptions {
1572
1696
  */
1573
1697
  readonly hostname?: Omit<HostnameOptions, "metavar" | "errors">;
1574
1698
  /**
1575
- * Options for IP validation (when type is "ip" or "both").
1576
- * Currently only supports IPv4.
1699
+ * IP version to accept when `type` is `"ip"` or `"both"`.
1700
+ * - `4`: IPv4 only
1701
+ * - `6`: IPv6 only
1702
+ * - `"both"`: Accept both IPv4 and IPv6
1703
+ *
1704
+ * @default `"both"` unless only the legacy {@link ip} field is set, in
1705
+ * which case the default is `4` to preserve IPv4-only compatibility.
1706
+ * @since 1.1.0
1707
+ */
1708
+ readonly version?: 4 | 6 | "both";
1709
+ /**
1710
+ * Options for IPv4 validation (when type is "ip" or "both").
1711
+ * This is kept for backwards compatibility; prefer {@link ipv4} for
1712
+ * new code.
1577
1713
  */
1578
1714
  readonly ip?: Omit<Ipv4Options, "metavar" | "errors">;
1715
+ /**
1716
+ * Options for IPv4 validation (when type is "ip" or "both").
1717
+ *
1718
+ * @since 1.1.0
1719
+ */
1720
+ readonly ipv4?: Omit<Ipv4Options, "metavar" | "errors">;
1721
+ /**
1722
+ * Options for IPv6 validation (when type is "ip" or "both").
1723
+ *
1724
+ * @since 1.1.0
1725
+ */
1726
+ readonly ipv6?: Omit<Ipv6Options, "metavar" | "errors">;
1579
1727
  };
1580
1728
  /**
1581
1729
  * Options for port validation.
@@ -1601,7 +1749,7 @@ interface SocketAddressOptions {
1601
1749
  * Creates a value parser for socket addresses in "host:port" format.
1602
1750
  *
1603
1751
  * Validates socket addresses with support for:
1604
- * - Hostnames and IPv4 addresses (IPv6 support coming in future versions)
1752
+ * - Hostnames, IPv4 addresses, and IPv6 addresses
1605
1753
  * - Configurable host:port separator
1606
1754
  * - Optional default port
1607
1755
  * - Host type filtering (hostname only, IP only, or both)
@@ -1612,6 +1760,8 @@ interface SocketAddressOptions {
1612
1760
  * @throws {TypeError} If `separator` is an empty string.
1613
1761
  * @throws {TypeError} If `separator` contains digit characters, since digits
1614
1762
  * in the separator would cause ambiguous splitting of port input.
1763
+ * @throws {TypeError} If `host.version` is provided but is not `4`, `6`, or
1764
+ * `"both"`.
1615
1765
  * @since 0.10.0
1616
1766
  *
1617
1767
  * @example
@@ -2908,4 +3058,4 @@ declare function firstOf<const TParsers extends readonly [ValueParser<"sync", un
2908
3058
  */
2909
3059
  declare function firstOf<const TParsers extends readonly ValueParser<"sync", unknown>[]>(parsers: TParsers, options?: FirstOfOptions): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
2910
3060
  //#endregion
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 };
3061
+ 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, KeyValueOptions, 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, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };