@optique/zod 1.0.0-dev.1354 → 1.0.0-dev.1361

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/index.cjs CHANGED
@@ -26,6 +26,20 @@ const __optique_core_nonempty = __toESM(require("@optique/core/nonempty"));
26
26
 
27
27
  //#region src/index.ts
28
28
  /**
29
+ * Checks whether the given error is a Zod async-parse error.
30
+ *
31
+ * - **Zod v4** throws a dedicated `$ZodAsyncError` class.
32
+ * - **Zod v3** (3.25+) throws a plain `Error` whose message starts with
33
+ * `"Async refinement encountered during synchronous parse operation"` for
34
+ * async refinements, or `"Asynchronous transform encountered during
35
+ * synchronous parse operation"` for async transforms.
36
+ */
37
+ function isZodAsyncError(error) {
38
+ if (error.constructor.name === "$ZodAsyncError") return true;
39
+ if (error.message === "Async refinement encountered during synchronous parse operation. Use .parseAsync instead." || error.message === "Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead." || error.message === "Synchronous parse encountered promise.") return true;
40
+ return false;
41
+ }
42
+ /**
29
43
  * Infers an appropriate metavar string from a Zod schema.
30
44
  *
31
45
  * This function analyzes the Zod schema's internal structure to determine
@@ -231,6 +245,8 @@ function inferChoices(schema) {
231
245
  * ```
232
246
  *
233
247
  * @throws {TypeError} If the resolved `metavar` is an empty string.
248
+ * @throws {TypeError} If the schema contains async refinements or other async
249
+ * operations that cannot be executed synchronously.
234
250
  * @since 0.7.0
235
251
  */
236
252
  function zod(schema, options = {}) {
@@ -250,7 +266,13 @@ function zod(schema, options = {}) {
250
266
  }
251
267
  } : {},
252
268
  parse(input) {
253
- const result = schema.safeParse(input);
269
+ let result;
270
+ try {
271
+ result = schema.safeParse(input);
272
+ } catch (error) {
273
+ if (error instanceof Error && isZodAsyncError(error)) throw new TypeError("Async Zod schemas (e.g., async refinements) are not supported by zod(). Use synchronous schemas instead.");
274
+ throw error;
275
+ }
254
276
  if (result.success) return {
255
277
  success: true,
256
278
  value: result.data
package/dist/index.d.cts CHANGED
@@ -98,6 +98,8 @@ interface ZodParserOptions {
98
98
  * ```
99
99
  *
100
100
  * @throws {TypeError} If the resolved `metavar` is an empty string.
101
+ * @throws {TypeError} If the schema contains async refinements or other async
102
+ * operations that cannot be executed synchronously.
101
103
  * @since 0.7.0
102
104
  */
103
105
  declare function zod<T>(schema: z.Schema<T>, options?: ZodParserOptions): ValueParser<"sync", T>;
package/dist/index.d.ts CHANGED
@@ -98,6 +98,8 @@ interface ZodParserOptions {
98
98
  * ```
99
99
  *
100
100
  * @throws {TypeError} If the resolved `metavar` is an empty string.
101
+ * @throws {TypeError} If the schema contains async refinements or other async
102
+ * operations that cannot be executed synchronously.
101
103
  * @since 0.7.0
102
104
  */
103
105
  declare function zod<T>(schema: z.Schema<T>, options?: ZodParserOptions): ValueParser<"sync", T>;
package/dist/index.js CHANGED
@@ -3,6 +3,20 @@ import { ensureNonEmptyString } from "@optique/core/nonempty";
3
3
 
4
4
  //#region src/index.ts
5
5
  /**
6
+ * Checks whether the given error is a Zod async-parse error.
7
+ *
8
+ * - **Zod v4** throws a dedicated `$ZodAsyncError` class.
9
+ * - **Zod v3** (3.25+) throws a plain `Error` whose message starts with
10
+ * `"Async refinement encountered during synchronous parse operation"` for
11
+ * async refinements, or `"Asynchronous transform encountered during
12
+ * synchronous parse operation"` for async transforms.
13
+ */
14
+ function isZodAsyncError(error) {
15
+ if (error.constructor.name === "$ZodAsyncError") return true;
16
+ if (error.message === "Async refinement encountered during synchronous parse operation. Use .parseAsync instead." || error.message === "Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead." || error.message === "Synchronous parse encountered promise.") return true;
17
+ return false;
18
+ }
19
+ /**
6
20
  * Infers an appropriate metavar string from a Zod schema.
7
21
  *
8
22
  * This function analyzes the Zod schema's internal structure to determine
@@ -208,6 +222,8 @@ function inferChoices(schema) {
208
222
  * ```
209
223
  *
210
224
  * @throws {TypeError} If the resolved `metavar` is an empty string.
225
+ * @throws {TypeError} If the schema contains async refinements or other async
226
+ * operations that cannot be executed synchronously.
211
227
  * @since 0.7.0
212
228
  */
213
229
  function zod(schema, options = {}) {
@@ -227,7 +243,13 @@ function zod(schema, options = {}) {
227
243
  }
228
244
  } : {},
229
245
  parse(input) {
230
- const result = schema.safeParse(input);
246
+ let result;
247
+ try {
248
+ result = schema.safeParse(input);
249
+ } catch (error) {
250
+ if (error instanceof Error && isZodAsyncError(error)) throw new TypeError("Async Zod schemas (e.g., async refinements) are not supported by zod(). Use synchronous schemas instead.");
251
+ throw error;
252
+ }
231
253
  if (result.success) return {
232
254
  success: true,
233
255
  value: result.data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/zod",
3
- "version": "1.0.0-dev.1354+b0af7b96",
3
+ "version": "1.0.0-dev.1361+c7adf09c",
4
4
  "description": "Zod value parsers for Optique",
5
5
  "keywords": [
6
6
  "CLI",
@@ -57,7 +57,7 @@
57
57
  "zod": "^3.25.0 || ^4.0.0"
58
58
  },
59
59
  "dependencies": {
60
- "@optique/core": "1.0.0-dev.1354+b0af7b96"
60
+ "@optique/core": "1.0.0-dev.1361+c7adf09c"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "^20.19.9",