@optique/core 1.0.0-dev.1499 → 1.0.0-dev.1500

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.
@@ -69,6 +69,21 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
69
69
  * @since 0.10.0
70
70
  */
71
71
  readonly choices?: readonly T[];
72
+ /**
73
+ * A type-appropriate default value used as a stand-in during deferred
74
+ * prompt resolution. When an interactive prompt is deferred during
75
+ * two-phase parsing, this value is used instead of an internal sentinel
76
+ * so that `map()` transforms and dynamic contexts always receive a valid
77
+ * value of type {@link T}.
78
+ *
79
+ * The placeholder does not need to be meaningful; it only needs to be
80
+ * a valid inhabitant of the result type that will not crash downstream
81
+ * transforms. For example, `string()` uses `""`, `integer()` uses `0`,
82
+ * and `choice(["a", "b", "c"])` uses `"a"`.
83
+ *
84
+ * @since 1.0.0
85
+ */
86
+ readonly placeholder: T;
72
87
  }
73
88
  /**
74
89
  * Result type returned by {@link ValueParser#parse}.
@@ -83,12 +98,48 @@ type ValueParserResult<T> = {
83
98
  readonly success: true;
84
99
  /** The successfully parsed value of type {@link T}. */
85
100
  readonly value: T;
101
+ /**
102
+ * When `true`, indicates that the value is a placeholder stand-in for
103
+ * a deferred interactive prompt, not a real user-provided value.
104
+ * Combinators propagate this flag so that the two-phase parsing
105
+ * facade can strip deferred values before passing them to phase-two
106
+ * contexts.
107
+ *
108
+ * @since 1.0.0
109
+ */
110
+ readonly deferred?: true;
111
+ /**
112
+ * A recursive map describing which property keys in {@link value} hold
113
+ * deferred placeholder values. Set by `object()`, `tuple()`, `merge()`,
114
+ * and other combinators. Intentionally not propagated by `map()` because
115
+ * opaque transforms invalidate the inner key set. Used by the two-phase
116
+ * facade to selectively replace only deferred fields with `undefined`
117
+ * while preserving non-deferred fields for phase-two context annotation
118
+ * collection.
119
+ *
120
+ * Each entry maps a property key to either `null` (the entire field is
121
+ * deferred) or another `DeferredMap` (the field is an object whose own
122
+ * sub-fields are partially deferred).
123
+ *
124
+ * @since 1.0.0
125
+ */
126
+ readonly deferredKeys?: DeferredMap;
86
127
  } | {
87
128
  /** Indicates that the parsing operation failed. */
88
129
  readonly success: false;
89
130
  /** The error message describing why the parsing failed. */
90
131
  readonly error: Message;
91
132
  };
133
+ /**
134
+ * A recursive map that tracks which fields in a parsed object hold deferred
135
+ * placeholder values. Each entry maps a property key to either `null`
136
+ * (the field is fully deferred and should be replaced with `undefined`)
137
+ * or another `DeferredMap` (the field is partially deferred — recurse into
138
+ * its sub-fields).
139
+ *
140
+ * @since 1.0.0
141
+ */
142
+ type DeferredMap = ReadonlyMap<PropertyKey, DeferredMap | null>;
92
143
  /**
93
144
  * Options for creating a string parser.
94
145
  */
@@ -112,6 +163,14 @@ interface StringOptions {
112
163
  * to validate patterns before use.
113
164
  */
114
165
  readonly pattern?: RegExp;
166
+ /**
167
+ * A custom placeholder value used during deferred prompt resolution.
168
+ * Override the default `""` when a `pattern` constraint or downstream
169
+ * `map()` transform requires a non-empty or specially shaped string.
170
+ *
171
+ * @since 1.0.0
172
+ */
173
+ readonly placeholder?: string;
115
174
  /**
116
175
  * Custom error messages for various string parsing failures.
117
176
  * @since 0.5.0
@@ -193,6 +252,9 @@ type ChoiceOptions = ChoiceOptionsString;
193
252
  * A predicate function that checks if an object is a {@link ValueParser}.
194
253
  * @param object The object to check.
195
254
  * @return `true` if the object is a {@link ValueParser}, `false` otherwise.
255
+ * @throws {TypeError} If the object looks like a value parser (has `$mode`,
256
+ * `metavar`, `parse`, and `format`) but is missing the required
257
+ * `placeholder` property.
196
258
  */
197
259
  declare function isValueParser<M extends Mode, T>(object: unknown): object is ValueParser<M, T>;
198
260
  /**
@@ -304,6 +366,14 @@ interface IntegerOptionsNumber {
304
366
  * no maximum is enforced.
305
367
  */
306
368
  readonly max?: number;
369
+ /**
370
+ * A custom placeholder value used during deferred prompt resolution.
371
+ * Override the default `0` when `min`/`max` constraints or downstream
372
+ * `map()` transforms require a specific value.
373
+ *
374
+ * @since 1.0.0
375
+ */
376
+ readonly placeholder?: number;
307
377
  /**
308
378
  * Custom error messages for integer parsing failures.
309
379
  * @since 0.5.0
@@ -362,6 +432,14 @@ interface IntegerOptionsBigInt {
362
432
  * no maximum is enforced.
363
433
  */
364
434
  readonly max?: bigint;
435
+ /**
436
+ * A custom placeholder value used during deferred prompt resolution.
437
+ * Override the default `0n` when `min`/`max` constraints or downstream
438
+ * `map()` transforms require a specific value.
439
+ *
440
+ * @since 1.0.0
441
+ */
442
+ readonly placeholder?: bigint;
365
443
  /**
366
444
  * Custom error messages for bigint integer parsing failures.
367
445
  * @since 0.5.0
@@ -436,6 +514,14 @@ interface FloatOptions {
436
514
  * @default `false`
437
515
  */
438
516
  readonly allowInfinity?: boolean;
517
+ /**
518
+ * A custom placeholder value used during deferred prompt resolution.
519
+ * Override the default `0` when `min`/`max` constraints or downstream
520
+ * `map()` transforms require a specific value.
521
+ *
522
+ * @since 1.0.0
523
+ */
524
+ readonly placeholder?: number;
439
525
  /**
440
526
  * Custom error messages for float parsing failures.
441
527
  * @since 0.5.0
@@ -689,6 +775,13 @@ interface PortOptionsNumber {
689
775
  * @default `false`
690
776
  */
691
777
  readonly disallowWellKnown?: boolean;
778
+ /**
779
+ * A custom placeholder value used during deferred prompt resolution.
780
+ * Defaults to `min` (which itself defaults to `1`).
781
+ *
782
+ * @since 1.0.0
783
+ */
784
+ readonly placeholder?: number;
692
785
  /**
693
786
  * Custom error messages for port parsing failures.
694
787
  * @since 0.10.0
@@ -751,6 +844,13 @@ interface PortOptionsBigInt {
751
844
  * @default `false`
752
845
  */
753
846
  readonly disallowWellKnown?: boolean;
847
+ /**
848
+ * A custom placeholder value used during deferred prompt resolution.
849
+ * Defaults to `min` (which itself defaults to `1n`).
850
+ *
851
+ * @since 1.0.0
852
+ */
853
+ readonly placeholder?: bigint;
754
854
  /**
755
855
  * Custom error messages for port parsing failures.
756
856
  * @since 0.10.0
@@ -949,6 +1049,13 @@ interface HostnameOptions {
949
1049
  * @default true
950
1050
  */
951
1051
  readonly allowLocalhost?: boolean;
1052
+ /**
1053
+ * A custom placeholder value used during deferred prompt resolution.
1054
+ * Override when `allowLocalhost` or other constraints reject the default.
1055
+ *
1056
+ * @since 1.0.0
1057
+ */
1058
+ readonly placeholder?: string;
952
1059
  /**
953
1060
  * Maximum hostname length in characters.
954
1061
  * @default 253
@@ -1054,6 +1161,13 @@ interface EmailOptions {
1054
1161
  * If specified, only emails from these domains are accepted.
1055
1162
  */
1056
1163
  readonly allowedDomains?: readonly string[];
1164
+ /**
1165
+ * Override the default placeholder value used for deferred parsing.
1166
+ * When not specified, the placeholder is derived from the first entry in
1167
+ * {@link allowedDomains} (or `"example.com"` when no domains are set).
1168
+ * @since 1.0.0
1169
+ */
1170
+ readonly placeholder?: string | readonly string[];
1057
1171
  /**
1058
1172
  * Custom error messages for email parsing failures.
1059
1173
  */
@@ -1086,6 +1200,8 @@ interface EmailOptions {
1086
1200
  * @throws {TypeError} If any `allowedDomains` entry is not a string, has
1087
1201
  * leading/trailing whitespace, starts with `"@"`, is empty, lacks a dot,
1088
1202
  * has invalid hostname label syntax, or is an IPv4-like dotted-quad.
1203
+ * @throws {TypeError} If `placeholder` type does not match `allowMultiple`
1204
+ * mode (string for single, array for multiple).
1089
1205
  * @since 0.10.0
1090
1206
  *
1091
1207
  * @example
@@ -1574,6 +1690,14 @@ interface DomainOptions {
1574
1690
  * @since 1.0.0
1575
1691
  */
1576
1692
  readonly maxLength?: number;
1693
+ /**
1694
+ * A custom placeholder value used during deferred prompt resolution.
1695
+ * Override when `allowedTlds`, `minLabels`, or other constraints
1696
+ * reject the default `"example.com"`.
1697
+ *
1698
+ * @since 1.0.0
1699
+ */
1700
+ readonly placeholder?: string;
1577
1701
  /**
1578
1702
  * If `true`, converts domain to lowercase.
1579
1703
  *
@@ -2015,4 +2139,4 @@ interface CidrOptions {
2015
2139
  */
2016
2140
  declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
2017
2141
  //#endregion
2018
- export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
2142
+ export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
@@ -69,6 +69,21 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
69
69
  * @since 0.10.0
70
70
  */
71
71
  readonly choices?: readonly T[];
72
+ /**
73
+ * A type-appropriate default value used as a stand-in during deferred
74
+ * prompt resolution. When an interactive prompt is deferred during
75
+ * two-phase parsing, this value is used instead of an internal sentinel
76
+ * so that `map()` transforms and dynamic contexts always receive a valid
77
+ * value of type {@link T}.
78
+ *
79
+ * The placeholder does not need to be meaningful; it only needs to be
80
+ * a valid inhabitant of the result type that will not crash downstream
81
+ * transforms. For example, `string()` uses `""`, `integer()` uses `0`,
82
+ * and `choice(["a", "b", "c"])` uses `"a"`.
83
+ *
84
+ * @since 1.0.0
85
+ */
86
+ readonly placeholder: T;
72
87
  }
73
88
  /**
74
89
  * Result type returned by {@link ValueParser#parse}.
@@ -83,12 +98,48 @@ type ValueParserResult<T> = {
83
98
  readonly success: true;
84
99
  /** The successfully parsed value of type {@link T}. */
85
100
  readonly value: T;
101
+ /**
102
+ * When `true`, indicates that the value is a placeholder stand-in for
103
+ * a deferred interactive prompt, not a real user-provided value.
104
+ * Combinators propagate this flag so that the two-phase parsing
105
+ * facade can strip deferred values before passing them to phase-two
106
+ * contexts.
107
+ *
108
+ * @since 1.0.0
109
+ */
110
+ readonly deferred?: true;
111
+ /**
112
+ * A recursive map describing which property keys in {@link value} hold
113
+ * deferred placeholder values. Set by `object()`, `tuple()`, `merge()`,
114
+ * and other combinators. Intentionally not propagated by `map()` because
115
+ * opaque transforms invalidate the inner key set. Used by the two-phase
116
+ * facade to selectively replace only deferred fields with `undefined`
117
+ * while preserving non-deferred fields for phase-two context annotation
118
+ * collection.
119
+ *
120
+ * Each entry maps a property key to either `null` (the entire field is
121
+ * deferred) or another `DeferredMap` (the field is an object whose own
122
+ * sub-fields are partially deferred).
123
+ *
124
+ * @since 1.0.0
125
+ */
126
+ readonly deferredKeys?: DeferredMap;
86
127
  } | {
87
128
  /** Indicates that the parsing operation failed. */
88
129
  readonly success: false;
89
130
  /** The error message describing why the parsing failed. */
90
131
  readonly error: Message;
91
132
  };
133
+ /**
134
+ * A recursive map that tracks which fields in a parsed object hold deferred
135
+ * placeholder values. Each entry maps a property key to either `null`
136
+ * (the field is fully deferred and should be replaced with `undefined`)
137
+ * or another `DeferredMap` (the field is partially deferred — recurse into
138
+ * its sub-fields).
139
+ *
140
+ * @since 1.0.0
141
+ */
142
+ type DeferredMap = ReadonlyMap<PropertyKey, DeferredMap | null>;
92
143
  /**
93
144
  * Options for creating a string parser.
94
145
  */
@@ -112,6 +163,14 @@ interface StringOptions {
112
163
  * to validate patterns before use.
113
164
  */
114
165
  readonly pattern?: RegExp;
166
+ /**
167
+ * A custom placeholder value used during deferred prompt resolution.
168
+ * Override the default `""` when a `pattern` constraint or downstream
169
+ * `map()` transform requires a non-empty or specially shaped string.
170
+ *
171
+ * @since 1.0.0
172
+ */
173
+ readonly placeholder?: string;
115
174
  /**
116
175
  * Custom error messages for various string parsing failures.
117
176
  * @since 0.5.0
@@ -193,6 +252,9 @@ type ChoiceOptions = ChoiceOptionsString;
193
252
  * A predicate function that checks if an object is a {@link ValueParser}.
194
253
  * @param object The object to check.
195
254
  * @return `true` if the object is a {@link ValueParser}, `false` otherwise.
255
+ * @throws {TypeError} If the object looks like a value parser (has `$mode`,
256
+ * `metavar`, `parse`, and `format`) but is missing the required
257
+ * `placeholder` property.
196
258
  */
197
259
  declare function isValueParser<M extends Mode, T>(object: unknown): object is ValueParser<M, T>;
198
260
  /**
@@ -304,6 +366,14 @@ interface IntegerOptionsNumber {
304
366
  * no maximum is enforced.
305
367
  */
306
368
  readonly max?: number;
369
+ /**
370
+ * A custom placeholder value used during deferred prompt resolution.
371
+ * Override the default `0` when `min`/`max` constraints or downstream
372
+ * `map()` transforms require a specific value.
373
+ *
374
+ * @since 1.0.0
375
+ */
376
+ readonly placeholder?: number;
307
377
  /**
308
378
  * Custom error messages for integer parsing failures.
309
379
  * @since 0.5.0
@@ -362,6 +432,14 @@ interface IntegerOptionsBigInt {
362
432
  * no maximum is enforced.
363
433
  */
364
434
  readonly max?: bigint;
435
+ /**
436
+ * A custom placeholder value used during deferred prompt resolution.
437
+ * Override the default `0n` when `min`/`max` constraints or downstream
438
+ * `map()` transforms require a specific value.
439
+ *
440
+ * @since 1.0.0
441
+ */
442
+ readonly placeholder?: bigint;
365
443
  /**
366
444
  * Custom error messages for bigint integer parsing failures.
367
445
  * @since 0.5.0
@@ -436,6 +514,14 @@ interface FloatOptions {
436
514
  * @default `false`
437
515
  */
438
516
  readonly allowInfinity?: boolean;
517
+ /**
518
+ * A custom placeholder value used during deferred prompt resolution.
519
+ * Override the default `0` when `min`/`max` constraints or downstream
520
+ * `map()` transforms require a specific value.
521
+ *
522
+ * @since 1.0.0
523
+ */
524
+ readonly placeholder?: number;
439
525
  /**
440
526
  * Custom error messages for float parsing failures.
441
527
  * @since 0.5.0
@@ -689,6 +775,13 @@ interface PortOptionsNumber {
689
775
  * @default `false`
690
776
  */
691
777
  readonly disallowWellKnown?: boolean;
778
+ /**
779
+ * A custom placeholder value used during deferred prompt resolution.
780
+ * Defaults to `min` (which itself defaults to `1`).
781
+ *
782
+ * @since 1.0.0
783
+ */
784
+ readonly placeholder?: number;
692
785
  /**
693
786
  * Custom error messages for port parsing failures.
694
787
  * @since 0.10.0
@@ -751,6 +844,13 @@ interface PortOptionsBigInt {
751
844
  * @default `false`
752
845
  */
753
846
  readonly disallowWellKnown?: boolean;
847
+ /**
848
+ * A custom placeholder value used during deferred prompt resolution.
849
+ * Defaults to `min` (which itself defaults to `1n`).
850
+ *
851
+ * @since 1.0.0
852
+ */
853
+ readonly placeholder?: bigint;
754
854
  /**
755
855
  * Custom error messages for port parsing failures.
756
856
  * @since 0.10.0
@@ -949,6 +1049,13 @@ interface HostnameOptions {
949
1049
  * @default true
950
1050
  */
951
1051
  readonly allowLocalhost?: boolean;
1052
+ /**
1053
+ * A custom placeholder value used during deferred prompt resolution.
1054
+ * Override when `allowLocalhost` or other constraints reject the default.
1055
+ *
1056
+ * @since 1.0.0
1057
+ */
1058
+ readonly placeholder?: string;
952
1059
  /**
953
1060
  * Maximum hostname length in characters.
954
1061
  * @default 253
@@ -1054,6 +1161,13 @@ interface EmailOptions {
1054
1161
  * If specified, only emails from these domains are accepted.
1055
1162
  */
1056
1163
  readonly allowedDomains?: readonly string[];
1164
+ /**
1165
+ * Override the default placeholder value used for deferred parsing.
1166
+ * When not specified, the placeholder is derived from the first entry in
1167
+ * {@link allowedDomains} (or `"example.com"` when no domains are set).
1168
+ * @since 1.0.0
1169
+ */
1170
+ readonly placeholder?: string | readonly string[];
1057
1171
  /**
1058
1172
  * Custom error messages for email parsing failures.
1059
1173
  */
@@ -1086,6 +1200,8 @@ interface EmailOptions {
1086
1200
  * @throws {TypeError} If any `allowedDomains` entry is not a string, has
1087
1201
  * leading/trailing whitespace, starts with `"@"`, is empty, lacks a dot,
1088
1202
  * has invalid hostname label syntax, or is an IPv4-like dotted-quad.
1203
+ * @throws {TypeError} If `placeholder` type does not match `allowMultiple`
1204
+ * mode (string for single, array for multiple).
1089
1205
  * @since 0.10.0
1090
1206
  *
1091
1207
  * @example
@@ -1574,6 +1690,14 @@ interface DomainOptions {
1574
1690
  * @since 1.0.0
1575
1691
  */
1576
1692
  readonly maxLength?: number;
1693
+ /**
1694
+ * A custom placeholder value used during deferred prompt resolution.
1695
+ * Override when `allowedTlds`, `minLabels`, or other constraints
1696
+ * reject the default `"example.com"`.
1697
+ *
1698
+ * @since 1.0.0
1699
+ */
1700
+ readonly placeholder?: string;
1577
1701
  /**
1578
1702
  * If `true`, converts domain to lowercase.
1579
1703
  *
@@ -2015,4 +2139,4 @@ interface CidrOptions {
2015
2139
  */
2016
2140
  declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
2017
2141
  //#endregion
2018
- export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
2142
+ export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };