@optique/valibot 0.10.7-dev.485 → 1.0.0-dev.1109

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
@@ -1,9 +1,6 @@
1
1
  @optique/valibot
2
2
  ================
3
3
 
4
- > [!WARNING]
5
- > The API is stabilizing, but may change before the 1.0 release.
6
-
7
4
  Valibot value parsers for Optique. This package provides seamless integration
8
5
  between [Valibot] schemas and *@optique/core*, enabling powerful validation and
9
6
  type-safe parsing of command-line arguments with minimal bundle size.
@@ -41,13 +38,16 @@ address.
41
38
 
42
39
  ~~~~ typescript
43
40
  import { run } from "@optique/run";
44
- import { option } from "@optique/core/parser";
41
+ import { object } from "@optique/core/constructs";
42
+ import { option } from "@optique/core/primitives";
45
43
  import { valibot } from "@optique/valibot";
46
44
  import * as v from "valibot";
47
45
 
48
- const cli = run({
49
- email: option("--email", valibot(v.pipe(v.string(), v.email()))),
50
- });
46
+ const cli = run(
47
+ object({
48
+ email: option("--email", valibot(v.pipe(v.string(), v.email()))),
49
+ }),
50
+ );
51
51
 
52
52
  console.log(`Welcome, ${cli.email}!`);
53
53
  ~~~~
@@ -69,6 +69,7 @@ Common use cases
69
69
  ### Email validation
70
70
 
71
71
  ~~~~ typescript
72
+ import { option } from "@optique/core/primitives";
72
73
  import { valibot } from "@optique/valibot";
73
74
  import * as v from "valibot";
74
75
 
@@ -78,6 +79,7 @@ const email = option("--email", valibot(v.pipe(v.string(), v.email())));
78
79
  ### URL validation
79
80
 
80
81
  ~~~~ typescript
82
+ import { option } from "@optique/core/primitives";
81
83
  import { valibot } from "@optique/valibot";
82
84
  import * as v from "valibot";
83
85
 
@@ -91,6 +93,7 @@ const url = option("--url", valibot(v.pipe(v.string(), v.url())));
91
93
  > non-string types, since CLI arguments are always strings.
92
94
 
93
95
  ~~~~ typescript
96
+ import { option } from "@optique/core/primitives";
94
97
  import { valibot } from "@optique/valibot";
95
98
  import * as v from "valibot";
96
99
 
@@ -109,6 +112,7 @@ const port = option("-p", "--port",
109
112
  ### Enum choices
110
113
 
111
114
  ~~~~ typescript
115
+ import { option } from "@optique/core/primitives";
112
116
  import { valibot } from "@optique/valibot";
113
117
  import * as v from "valibot";
114
118
 
@@ -120,11 +124,12 @@ const logLevel = option("--log-level",
120
124
  ### Date transformations
121
125
 
122
126
  ~~~~ typescript
127
+ import { argument } from "@optique/core/primitives";
123
128
  import { valibot } from "@optique/valibot";
124
129
  import * as v from "valibot";
125
130
 
126
131
  const startDate = argument(
127
- valibot(v.pipe(v.string(), v.transform((s) => new Date(s))))
132
+ valibot(v.pipe(v.string(), v.transform((s: string) => new Date(s))))
128
133
  );
129
134
  ~~~~
130
135
 
@@ -135,6 +140,7 @@ Custom error messages
135
140
  You can customize error messages using the `errors` option:
136
141
 
137
142
  ~~~~ typescript
143
+ import { option } from "@optique/core/primitives";
138
144
  import { valibot } from "@optique/valibot";
139
145
  import { message } from "@optique/core/message";
140
146
  import * as v from "valibot";
@@ -158,11 +164,15 @@ CLI arguments are always strings. If you want to parse numbers, booleans,
158
164
  or other types, you must use explicit `v.transform()`:
159
165
 
160
166
  ~~~~ typescript
167
+ import { option } from "@optique/core/primitives";
168
+ import { valibot } from "@optique/valibot";
169
+ import * as v from "valibot";
170
+
161
171
  // ✅ Correct
162
172
  const port = option("-p", valibot(v.pipe(v.string(), v.transform(Number))));
163
173
 
164
174
  // ❌ Won't work (CLI arguments are always strings)
165
- const port = option("-p", valibot(v.number()));
175
+ // const port = option("-p", valibot(v.number()));
166
176
  ~~~~
167
177
 
168
178
  ### Async validations are not supported
@@ -171,6 +181,10 @@ Optique's `ValueParser.parse()` is synchronous, so async Valibot features like
171
181
  async validations cannot be supported:
172
182
 
173
183
  ~~~~ typescript
184
+ import { option } from "@optique/core/primitives";
185
+ import { valibot } from "@optique/valibot";
186
+ import * as v from "valibot";
187
+
174
188
  // ❌ Not supported
175
189
  const email = option("--email",
176
190
  valibot(v.pipeAsync(v.string(), v.checkAsync(async (val) => await checkDB(val))))
package/dist/index.cjs CHANGED
@@ -46,10 +46,11 @@ const valibot = __toESM(require("valibot"));
46
46
  * @since 0.7.0
47
47
  */
48
48
  function inferMetavar(schema) {
49
- const schemaType = schema.type;
49
+ const internalSchema = schema;
50
+ const schemaType = internalSchema.type;
50
51
  if (!schemaType) return "VALUE";
51
52
  if (schemaType === "string") {
52
- const pipeline = schema.pipe;
53
+ const pipeline = internalSchema.pipe;
53
54
  if (Array.isArray(pipeline)) for (const action of pipeline) {
54
55
  const actionType = action.type;
55
56
  if (actionType === "transform") return "VALUE";
@@ -71,7 +72,7 @@ function inferMetavar(schema) {
71
72
  return "STRING";
72
73
  }
73
74
  if (schemaType === "number") {
74
- const pipeline = schema.pipe;
75
+ const pipeline = internalSchema.pipe;
75
76
  if (Array.isArray(pipeline)) for (const action of pipeline) {
76
77
  const actionType = action.type;
77
78
  if (actionType === "transform") return "VALUE";
@@ -85,7 +86,7 @@ function inferMetavar(schema) {
85
86
  if (schemaType === "literal") return "VALUE";
86
87
  if (schemaType === "union" || schemaType === "variant") return "VALUE";
87
88
  if (schemaType === "optional" || schemaType === "nullable" || schemaType === "nullish") {
88
- const wrapped = schema.wrapped;
89
+ const wrapped = internalSchema.wrapped;
89
90
  if (wrapped) return inferMetavar(wrapped);
90
91
  }
91
92
  return "VALUE";
package/dist/index.js CHANGED
@@ -23,10 +23,11 @@ import { safeParse } from "valibot";
23
23
  * @since 0.7.0
24
24
  */
25
25
  function inferMetavar(schema) {
26
- const schemaType = schema.type;
26
+ const internalSchema = schema;
27
+ const schemaType = internalSchema.type;
27
28
  if (!schemaType) return "VALUE";
28
29
  if (schemaType === "string") {
29
- const pipeline = schema.pipe;
30
+ const pipeline = internalSchema.pipe;
30
31
  if (Array.isArray(pipeline)) for (const action of pipeline) {
31
32
  const actionType = action.type;
32
33
  if (actionType === "transform") return "VALUE";
@@ -48,7 +49,7 @@ function inferMetavar(schema) {
48
49
  return "STRING";
49
50
  }
50
51
  if (schemaType === "number") {
51
- const pipeline = schema.pipe;
52
+ const pipeline = internalSchema.pipe;
52
53
  if (Array.isArray(pipeline)) for (const action of pipeline) {
53
54
  const actionType = action.type;
54
55
  if (actionType === "transform") return "VALUE";
@@ -62,7 +63,7 @@ function inferMetavar(schema) {
62
63
  if (schemaType === "literal") return "VALUE";
63
64
  if (schemaType === "union" || schemaType === "variant") return "VALUE";
64
65
  if (schemaType === "optional" || schemaType === "nullable" || schemaType === "nullish") {
65
- const wrapped = schema.wrapped;
66
+ const wrapped = internalSchema.wrapped;
66
67
  if (wrapped) return inferMetavar(wrapped);
67
68
  }
68
69
  return "VALUE";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/valibot",
3
- "version": "0.10.7-dev.485+0a30b635",
3
+ "version": "1.0.0-dev.1109+fa132665",
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": "0.10.7-dev.485+0a30b635"
60
+ "@optique/core": "1.0.0-dev.1109+fa132665"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "^20.19.9",