@optique/valibot 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.
package/README.md CHANGED
@@ -45,7 +45,9 @@ import * as v from "valibot";
45
45
 
46
46
  const cli = run(
47
47
  object({
48
- email: option("--email", valibot(v.pipe(v.string(), v.email()))),
48
+ email: option("--email",
49
+ valibot(v.pipe(v.string(), v.email()), { placeholder: "" }),
50
+ ),
49
51
  }),
50
52
  );
51
53
 
@@ -73,7 +75,9 @@ import { option } from "@optique/core/primitives";
73
75
  import { valibot } from "@optique/valibot";
74
76
  import * as v from "valibot";
75
77
 
76
- const email = option("--email", valibot(v.pipe(v.string(), v.email())));
78
+ const email = option("--email",
79
+ valibot(v.pipe(v.string(), v.email()), { placeholder: "" }),
80
+ );
77
81
  ~~~~
78
82
 
79
83
  ### URL validation
@@ -83,7 +87,9 @@ import { option } from "@optique/core/primitives";
83
87
  import { valibot } from "@optique/valibot";
84
88
  import * as v from "valibot";
85
89
 
86
- const url = option("--url", valibot(v.pipe(v.string(), v.url())));
90
+ const url = option("--url",
91
+ valibot(v.pipe(v.string(), v.url()), { placeholder: "" }),
92
+ );
87
93
  ~~~~
88
94
 
89
95
  ### Port numbers with range validation
@@ -105,7 +111,7 @@ const port = option("-p", "--port",
105
111
  v.integer(),
106
112
  v.minValue(1024),
107
113
  v.maxValue(65535)
108
- ))
114
+ ), { placeholder: 0 }),
109
115
  );
110
116
  ~~~~
111
117
 
@@ -117,7 +123,8 @@ import { valibot } from "@optique/valibot";
117
123
  import * as v from "valibot";
118
124
 
119
125
  const logLevel = option("--log-level",
120
- valibot(v.picklist(["debug", "info", "warn", "error"]))
126
+ valibot(v.picklist(["debug", "info", "warn", "error"]),
127
+ { placeholder: "debug" }),
121
128
  );
122
129
  ~~~~
123
130
 
@@ -129,7 +136,8 @@ import { valibot } from "@optique/valibot";
129
136
  import * as v from "valibot";
130
137
 
131
138
  const startDate = argument(
132
- valibot(v.pipe(v.string(), v.transform((s: string) => new Date(s))))
139
+ valibot(v.pipe(v.string(), v.transform((s: string) => new Date(s))),
140
+ { placeholder: new Date(0) }),
133
141
  );
134
142
  ~~~~
135
143
 
@@ -146,6 +154,7 @@ import { message } from "@optique/core/message";
146
154
  import * as v from "valibot";
147
155
 
148
156
  const email = option("--email", valibot(v.pipe(v.string(), v.email()), {
157
+ placeholder: "",
149
158
  metavar: "EMAIL",
150
159
  errors: {
151
160
  valibotError: (issues, input) =>
@@ -169,7 +178,9 @@ import { valibot } from "@optique/valibot";
169
178
  import * as v from "valibot";
170
179
 
171
180
  // ✅ Correct
172
- const port = option("-p", valibot(v.pipe(v.string(), v.transform(Number))));
181
+ const port = option("-p",
182
+ valibot(v.pipe(v.string(), v.transform(Number)), { placeholder: 0 }),
183
+ );
173
184
 
174
185
  // ❌ Won't work (CLI arguments are always strings)
175
186
  // const port = option("-p", valibot(v.number()));
@@ -187,7 +198,9 @@ import * as v from "valibot";
187
198
 
188
199
  // ❌ Not supported
189
200
  const email = option("--email",
190
- valibot(v.pipeAsync(v.string(), v.checkAsync(async (val) => await checkDB(val))))
201
+ valibot(v.pipeAsync(v.string(),
202
+ v.checkAsync(async (val) => await checkDB(val))),
203
+ { placeholder: "" }),
191
204
  );
192
205
  ~~~~
193
206
 
package/dist/index.cjs CHANGED
@@ -302,7 +302,8 @@ function inferChoices(schema) {
302
302
  *
303
303
  * @template T The output type of the Valibot schema.
304
304
  * @param schema A Valibot schema to validate input against.
305
- * @param options Optional configuration for the parser.
305
+ * @param options Configuration for the parser, including a required
306
+ * `placeholder` value used during deferred prompt resolution.
306
307
  * @returns A value parser that validates inputs using the provided schema.
307
308
  *
308
309
  * @example Basic string validation
@@ -311,7 +312,9 @@ function inferChoices(schema) {
311
312
  * import { valibot } from "@optique/valibot";
312
313
  * import { option } from "@optique/core/primitives";
313
314
  *
314
- * const email = option("--email", valibot(v.pipe(v.string(), v.email())));
315
+ * const email = option("--email",
316
+ * valibot(v.pipe(v.string(), v.email()), { placeholder: "" }),
317
+ * );
315
318
  * ```
316
319
  *
317
320
  * @example Number validation with pipeline
@@ -328,8 +331,8 @@ function inferChoices(schema) {
328
331
  * v.number(),
329
332
  * v.integer(),
330
333
  * v.minValue(1024),
331
- * v.maxValue(65535)
332
- * ))
334
+ * v.maxValue(65535),
335
+ * ), { placeholder: 1024 }),
333
336
  * );
334
337
  * ```
335
338
  *
@@ -340,7 +343,9 @@ function inferChoices(schema) {
340
343
  * import { option } from "@optique/core/primitives";
341
344
  *
342
345
  * const logLevel = option("--log-level",
343
- * valibot(v.picklist(["debug", "info", "warn", "error"]))
346
+ * valibot(v.picklist(["debug", "info", "warn", "error"]), {
347
+ * placeholder: "debug",
348
+ * }),
344
349
  * );
345
350
  * ```
346
351
  *
@@ -353,21 +358,26 @@ function inferChoices(schema) {
353
358
  *
354
359
  * const email = option("--email",
355
360
  * valibot(v.pipe(v.string(), v.email()), {
361
+ * placeholder: "",
356
362
  * metavar: "EMAIL",
357
363
  * errors: {
358
364
  * valibotError: (issues, input) =>
359
365
  * message`Please provide a valid email address, got ${input}.`
360
- * }
361
- * })
366
+ * },
367
+ * }),
362
368
  * );
363
369
  * ```
364
370
  *
371
+ * @throws {TypeError} If `options` is missing, not an object, or does not
372
+ * include `placeholder`.
365
373
  * @throws {TypeError} If the resolved `metavar` is an empty string.
366
374
  * @throws {TypeError} If the schema contains async validations that cannot be
367
375
  * executed synchronously.
368
376
  * @since 0.7.0
369
377
  */
370
- function valibot$1(schema, options = {}) {
378
+ function valibot$1(schema, options) {
379
+ if (options == null || typeof options !== "object") throw new TypeError("valibot() requires an options object with a placeholder property.");
380
+ if (!("placeholder" in options)) throw new TypeError("valibot() options must include a placeholder property.");
371
381
  if (containsAsyncSchema(schema)) throw new TypeError("Async Valibot schemas (e.g., async validations) are not supported by valibot(). Use synchronous schemas instead.");
372
382
  const choices = inferChoices(schema);
373
383
  const metavar = options.metavar ?? inferMetavar(schema);
@@ -375,6 +385,7 @@ function valibot$1(schema, options = {}) {
375
385
  const parser = {
376
386
  $mode: "sync",
377
387
  metavar,
388
+ placeholder: options.placeholder,
378
389
  ...choices != null && choices.length > 0 ? {
379
390
  choices: Object.freeze(choices),
380
391
  *suggest(prefix) {
package/dist/index.d.cts CHANGED
@@ -16,6 +16,13 @@ interface ValibotParserOptions<T = unknown> {
16
16
  * @default `"VALUE"`
17
17
  */
18
18
  readonly metavar?: NonEmptyString;
19
+ /**
20
+ * A phase-one stand-in value of type `T` used during deferred prompt
21
+ * resolution. Because the output type of a Valibot schema cannot be
22
+ * inferred to a concrete default, callers must provide this explicitly.
23
+ * @since 1.0.0
24
+ */
25
+ readonly placeholder: T;
19
26
  /**
20
27
  * Custom formatter for displaying parsed values in help messages.
21
28
  * When not provided, the default formatter is used: primitives use
@@ -58,7 +65,8 @@ interface ValibotParserOptions<T = unknown> {
58
65
  *
59
66
  * @template T The output type of the Valibot schema.
60
67
  * @param schema A Valibot schema to validate input against.
61
- * @param options Optional configuration for the parser.
68
+ * @param options Configuration for the parser, including a required
69
+ * `placeholder` value used during deferred prompt resolution.
62
70
  * @returns A value parser that validates inputs using the provided schema.
63
71
  *
64
72
  * @example Basic string validation
@@ -67,7 +75,9 @@ interface ValibotParserOptions<T = unknown> {
67
75
  * import { valibot } from "@optique/valibot";
68
76
  * import { option } from "@optique/core/primitives";
69
77
  *
70
- * const email = option("--email", valibot(v.pipe(v.string(), v.email())));
78
+ * const email = option("--email",
79
+ * valibot(v.pipe(v.string(), v.email()), { placeholder: "" }),
80
+ * );
71
81
  * ```
72
82
  *
73
83
  * @example Number validation with pipeline
@@ -84,8 +94,8 @@ interface ValibotParserOptions<T = unknown> {
84
94
  * v.number(),
85
95
  * v.integer(),
86
96
  * v.minValue(1024),
87
- * v.maxValue(65535)
88
- * ))
97
+ * v.maxValue(65535),
98
+ * ), { placeholder: 1024 }),
89
99
  * );
90
100
  * ```
91
101
  *
@@ -96,7 +106,9 @@ interface ValibotParserOptions<T = unknown> {
96
106
  * import { option } from "@optique/core/primitives";
97
107
  *
98
108
  * const logLevel = option("--log-level",
99
- * valibot(v.picklist(["debug", "info", "warn", "error"]))
109
+ * valibot(v.picklist(["debug", "info", "warn", "error"]), {
110
+ * placeholder: "debug",
111
+ * }),
100
112
  * );
101
113
  * ```
102
114
  *
@@ -109,20 +121,23 @@ interface ValibotParserOptions<T = unknown> {
109
121
  *
110
122
  * const email = option("--email",
111
123
  * valibot(v.pipe(v.string(), v.email()), {
124
+ * placeholder: "",
112
125
  * metavar: "EMAIL",
113
126
  * errors: {
114
127
  * valibotError: (issues, input) =>
115
128
  * message`Please provide a valid email address, got ${input}.`
116
- * }
117
- * })
129
+ * },
130
+ * }),
118
131
  * );
119
132
  * ```
120
133
  *
134
+ * @throws {TypeError} If `options` is missing, not an object, or does not
135
+ * include `placeholder`.
121
136
  * @throws {TypeError} If the resolved `metavar` is an empty string.
122
137
  * @throws {TypeError} If the schema contains async validations that cannot be
123
138
  * executed synchronously.
124
139
  * @since 0.7.0
125
140
  */
126
- declare function valibot<T>(schema: v.BaseSchema<unknown, T, v.BaseIssue<unknown>>, options?: ValibotParserOptions<T>): ValueParser<"sync", T>;
141
+ declare function valibot<T>(schema: v.BaseSchema<unknown, T, v.BaseIssue<unknown>>, options: ValibotParserOptions<T>): ValueParser<"sync", T>;
127
142
  //#endregion
128
143
  export { ValibotParserOptions, valibot };
package/dist/index.d.ts CHANGED
@@ -16,6 +16,13 @@ interface ValibotParserOptions<T = unknown> {
16
16
  * @default `"VALUE"`
17
17
  */
18
18
  readonly metavar?: NonEmptyString;
19
+ /**
20
+ * A phase-one stand-in value of type `T` used during deferred prompt
21
+ * resolution. Because the output type of a Valibot schema cannot be
22
+ * inferred to a concrete default, callers must provide this explicitly.
23
+ * @since 1.0.0
24
+ */
25
+ readonly placeholder: T;
19
26
  /**
20
27
  * Custom formatter for displaying parsed values in help messages.
21
28
  * When not provided, the default formatter is used: primitives use
@@ -58,7 +65,8 @@ interface ValibotParserOptions<T = unknown> {
58
65
  *
59
66
  * @template T The output type of the Valibot schema.
60
67
  * @param schema A Valibot schema to validate input against.
61
- * @param options Optional configuration for the parser.
68
+ * @param options Configuration for the parser, including a required
69
+ * `placeholder` value used during deferred prompt resolution.
62
70
  * @returns A value parser that validates inputs using the provided schema.
63
71
  *
64
72
  * @example Basic string validation
@@ -67,7 +75,9 @@ interface ValibotParserOptions<T = unknown> {
67
75
  * import { valibot } from "@optique/valibot";
68
76
  * import { option } from "@optique/core/primitives";
69
77
  *
70
- * const email = option("--email", valibot(v.pipe(v.string(), v.email())));
78
+ * const email = option("--email",
79
+ * valibot(v.pipe(v.string(), v.email()), { placeholder: "" }),
80
+ * );
71
81
  * ```
72
82
  *
73
83
  * @example Number validation with pipeline
@@ -84,8 +94,8 @@ interface ValibotParserOptions<T = unknown> {
84
94
  * v.number(),
85
95
  * v.integer(),
86
96
  * v.minValue(1024),
87
- * v.maxValue(65535)
88
- * ))
97
+ * v.maxValue(65535),
98
+ * ), { placeholder: 1024 }),
89
99
  * );
90
100
  * ```
91
101
  *
@@ -96,7 +106,9 @@ interface ValibotParserOptions<T = unknown> {
96
106
  * import { option } from "@optique/core/primitives";
97
107
  *
98
108
  * const logLevel = option("--log-level",
99
- * valibot(v.picklist(["debug", "info", "warn", "error"]))
109
+ * valibot(v.picklist(["debug", "info", "warn", "error"]), {
110
+ * placeholder: "debug",
111
+ * }),
100
112
  * );
101
113
  * ```
102
114
  *
@@ -109,20 +121,23 @@ interface ValibotParserOptions<T = unknown> {
109
121
  *
110
122
  * const email = option("--email",
111
123
  * valibot(v.pipe(v.string(), v.email()), {
124
+ * placeholder: "",
112
125
  * metavar: "EMAIL",
113
126
  * errors: {
114
127
  * valibotError: (issues, input) =>
115
128
  * message`Please provide a valid email address, got ${input}.`
116
- * }
117
- * })
129
+ * },
130
+ * }),
118
131
  * );
119
132
  * ```
120
133
  *
134
+ * @throws {TypeError} If `options` is missing, not an object, or does not
135
+ * include `placeholder`.
121
136
  * @throws {TypeError} If the resolved `metavar` is an empty string.
122
137
  * @throws {TypeError} If the schema contains async validations that cannot be
123
138
  * executed synchronously.
124
139
  * @since 0.7.0
125
140
  */
126
- declare function valibot<T>(schema: v.BaseSchema<unknown, T, v.BaseIssue<unknown>>, options?: ValibotParserOptions<T>): ValueParser<"sync", T>;
141
+ declare function valibot<T>(schema: v.BaseSchema<unknown, T, v.BaseIssue<unknown>>, options: ValibotParserOptions<T>): ValueParser<"sync", T>;
127
142
  //#endregion
128
143
  export { ValibotParserOptions, valibot };
package/dist/index.js CHANGED
@@ -279,7 +279,8 @@ function inferChoices(schema) {
279
279
  *
280
280
  * @template T The output type of the Valibot schema.
281
281
  * @param schema A Valibot schema to validate input against.
282
- * @param options Optional configuration for the parser.
282
+ * @param options Configuration for the parser, including a required
283
+ * `placeholder` value used during deferred prompt resolution.
283
284
  * @returns A value parser that validates inputs using the provided schema.
284
285
  *
285
286
  * @example Basic string validation
@@ -288,7 +289,9 @@ function inferChoices(schema) {
288
289
  * import { valibot } from "@optique/valibot";
289
290
  * import { option } from "@optique/core/primitives";
290
291
  *
291
- * const email = option("--email", valibot(v.pipe(v.string(), v.email())));
292
+ * const email = option("--email",
293
+ * valibot(v.pipe(v.string(), v.email()), { placeholder: "" }),
294
+ * );
292
295
  * ```
293
296
  *
294
297
  * @example Number validation with pipeline
@@ -305,8 +308,8 @@ function inferChoices(schema) {
305
308
  * v.number(),
306
309
  * v.integer(),
307
310
  * v.minValue(1024),
308
- * v.maxValue(65535)
309
- * ))
311
+ * v.maxValue(65535),
312
+ * ), { placeholder: 1024 }),
310
313
  * );
311
314
  * ```
312
315
  *
@@ -317,7 +320,9 @@ function inferChoices(schema) {
317
320
  * import { option } from "@optique/core/primitives";
318
321
  *
319
322
  * const logLevel = option("--log-level",
320
- * valibot(v.picklist(["debug", "info", "warn", "error"]))
323
+ * valibot(v.picklist(["debug", "info", "warn", "error"]), {
324
+ * placeholder: "debug",
325
+ * }),
321
326
  * );
322
327
  * ```
323
328
  *
@@ -330,21 +335,26 @@ function inferChoices(schema) {
330
335
  *
331
336
  * const email = option("--email",
332
337
  * valibot(v.pipe(v.string(), v.email()), {
338
+ * placeholder: "",
333
339
  * metavar: "EMAIL",
334
340
  * errors: {
335
341
  * valibotError: (issues, input) =>
336
342
  * message`Please provide a valid email address, got ${input}.`
337
- * }
338
- * })
343
+ * },
344
+ * }),
339
345
  * );
340
346
  * ```
341
347
  *
348
+ * @throws {TypeError} If `options` is missing, not an object, or does not
349
+ * include `placeholder`.
342
350
  * @throws {TypeError} If the resolved `metavar` is an empty string.
343
351
  * @throws {TypeError} If the schema contains async validations that cannot be
344
352
  * executed synchronously.
345
353
  * @since 0.7.0
346
354
  */
347
- function valibot(schema, options = {}) {
355
+ function valibot(schema, options) {
356
+ if (options == null || typeof options !== "object") throw new TypeError("valibot() requires an options object with a placeholder property.");
357
+ if (!("placeholder" in options)) throw new TypeError("valibot() options must include a placeholder property.");
348
358
  if (containsAsyncSchema(schema)) throw new TypeError("Async Valibot schemas (e.g., async validations) are not supported by valibot(). Use synchronous schemas instead.");
349
359
  const choices = inferChoices(schema);
350
360
  const metavar = options.metavar ?? inferMetavar(schema);
@@ -352,6 +362,7 @@ function valibot(schema, options = {}) {
352
362
  const parser = {
353
363
  $mode: "sync",
354
364
  metavar,
365
+ placeholder: options.placeholder,
355
366
  ...choices != null && choices.length > 0 ? {
356
367
  choices: Object.freeze(choices),
357
368
  *suggest(prefix) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/valibot",
3
- "version": "1.0.0-dev.1499+1fd447f6",
3
+ "version": "1.0.0-dev.1500+dc0650e5",
4
4
  "description": "Valibot value parsers for Optique",
5
5
  "keywords": [
6
6
  "CLI",
@@ -57,7 +57,7 @@
57
57
  "valibot": "^1.2.0"
58
58
  },
59
59
  "dependencies": {
60
- "@optique/core": "1.0.0-dev.1499+1fd447f6"
60
+ "@optique/core": "1.0.0-dev.1500+dc0650e5"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "^20.19.9",