@orpc/zod 0.0.0-next.fd13879 → 0.0.0-next.fd6982a

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.
@@ -2,7 +2,7 @@ import { Context } from '@orpc/server';
2
2
  import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
3
3
  import { AnySchema } from '@orpc/contract';
4
4
  import { JSONSchema, SchemaConvertOptions, ConditionalSchemaConverter } from '@orpc/openapi';
5
- import { Interceptor, ThrowableError, Promisable } from '@orpc/shared';
5
+ import { Interceptor } from '@orpc/shared';
6
6
  import * as zod_v4_core from 'zod/v4/core';
7
7
  import { $ZodType, $input, $output } from 'zod/v4/core';
8
8
 
@@ -46,7 +46,7 @@ interface experimental_ZodToJsonSchemaOptions {
46
46
  }, [
47
47
  required: boolean,
48
48
  jsonSchema: Exclude<JSONSchema, boolean>
49
- ], ThrowableError>[];
49
+ ]>[];
50
50
  }
51
51
  declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
52
52
  #private;
@@ -57,7 +57,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
57
57
  private readonly interceptors;
58
58
  constructor(options?: experimental_ZodToJsonSchemaOptions);
59
59
  condition(schema: AnySchema | undefined): boolean;
60
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: Exclude<JSONSchema, boolean>]>;
60
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
61
61
  }
62
62
 
63
63
  /**
@@ -2,7 +2,7 @@ import { Context } from '@orpc/server';
2
2
  import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
3
3
  import { AnySchema } from '@orpc/contract';
4
4
  import { JSONSchema, SchemaConvertOptions, ConditionalSchemaConverter } from '@orpc/openapi';
5
- import { Interceptor, ThrowableError, Promisable } from '@orpc/shared';
5
+ import { Interceptor } from '@orpc/shared';
6
6
  import * as zod_v4_core from 'zod/v4/core';
7
7
  import { $ZodType, $input, $output } from 'zod/v4/core';
8
8
 
@@ -46,7 +46,7 @@ interface experimental_ZodToJsonSchemaOptions {
46
46
  }, [
47
47
  required: boolean,
48
48
  jsonSchema: Exclude<JSONSchema, boolean>
49
- ], ThrowableError>[];
49
+ ]>[];
50
50
  }
51
51
  declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
52
52
  #private;
@@ -57,7 +57,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
57
57
  private readonly interceptors;
58
58
  constructor(options?: experimental_ZodToJsonSchemaOptions);
59
59
  condition(schema: AnySchema | undefined): boolean;
60
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: Exclude<JSONSchema, boolean>]>;
60
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
61
61
  }
62
62
 
63
63
  /**
@@ -308,11 +308,11 @@ class experimental_ZodToJsonSchemaConverter {
308
308
  return intercept(
309
309
  this.interceptors,
310
310
  { schema, options, lazyDepth, isHandledCustomJSONSchema },
311
- async ({ schema: schema2, options: options2, lazyDepth: lazyDepth2, isHandledCustomJSONSchema: isHandledCustomJSONSchema2 }) => {
311
+ ({ schema: schema2, options: options2, lazyDepth: lazyDepth2, isHandledCustomJSONSchema: isHandledCustomJSONSchema2 }) => {
312
312
  if (!isHandledCustomJSONSchema2) {
313
313
  const customJSONSchema = this.#getCustomJsonSchema(schema2, options2);
314
314
  if (customJSONSchema) {
315
- const [required, json] = await this.#convert(schema2, options2, lazyDepth2, true);
315
+ const [required, json] = this.#convert(schema2, options2, lazyDepth2, true);
316
316
  return [required, { ...json, ...customJSONSchema }];
317
317
  }
318
318
  }
@@ -320,20 +320,20 @@ class experimental_ZodToJsonSchemaConverter {
320
320
  case "string": {
321
321
  const string = schema2;
322
322
  const json = { type: "string" };
323
- const { minimum, maximum, format, pattern, contentEncoding } = string._zod.computed;
324
- if (minimum !== void 0) {
323
+ const { minimum, maximum, format, pattern, contentEncoding } = string._zod.bag;
324
+ if (typeof minimum === "number") {
325
325
  json.minLength = minimum;
326
326
  }
327
- if (maximum !== void 0) {
327
+ if (typeof maximum === "number") {
328
328
  json.maxLength = maximum;
329
329
  }
330
- if (contentEncoding !== void 0) {
330
+ if (typeof contentEncoding === "string") {
331
331
  json.contentEncoding = this.#handleContentEncoding(contentEncoding);
332
332
  }
333
- if (format !== void 0 && format !== "regex" && json.contentEncoding === void 0) {
333
+ if (typeof format === "string" && format !== "regex" && json.contentEncoding === void 0) {
334
334
  json.format = this.#handleStringFormat(format);
335
335
  }
336
- if (pattern !== void 0 && json.contentEncoding === void 0 && json.format === void 0) {
336
+ if (pattern instanceof RegExp && json.contentEncoding === void 0 && json.format === void 0) {
337
337
  json.pattern = pattern.source;
338
338
  }
339
339
  if (format === "jwt" && json.contentEncoding === void 0 && json.format === void 0 && json.pattern === void 0) {
@@ -344,25 +344,23 @@ class experimental_ZodToJsonSchemaConverter {
344
344
  case "number": {
345
345
  const number = schema2;
346
346
  const json = { type: "number" };
347
- const { minimum, maximum, format, multipleOf, inclusive } = number._zod.computed;
348
- if (format?.includes("int")) {
347
+ const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = number._zod.bag;
348
+ if (typeof format === "string" && format?.includes("int")) {
349
349
  json.type = "integer";
350
350
  }
351
- if (minimum !== void 0) {
352
- if (inclusive) {
353
- json.minimum = minimum;
354
- } else {
355
- json.exclusiveMinimum = minimum;
356
- }
351
+ if (typeof minimum === "number") {
352
+ json.minimum = minimum;
357
353
  }
358
- if (maximum !== void 0) {
359
- if (inclusive) {
360
- json.maximum = maximum;
361
- } else {
362
- json.exclusiveMaximum = maximum;
363
- }
354
+ if (typeof maximum === "number") {
355
+ json.maximum = maximum;
364
356
  }
365
- if (multipleOf !== void 0) {
357
+ if (typeof exclusiveMinimum === "number") {
358
+ json.exclusiveMinimum = exclusiveMinimum;
359
+ }
360
+ if (typeof exclusiveMaximum === "number") {
361
+ json.exclusiveMaximum = exclusiveMaximum;
362
+ }
363
+ if (typeof multipleOf === "number") {
366
364
  json.multipleOf = multipleOf;
367
365
  }
368
366
  return [true, json];
@@ -395,21 +393,21 @@ class experimental_ZodToJsonSchemaConverter {
395
393
  case "array": {
396
394
  const array = schema2;
397
395
  const json = { type: "array" };
398
- const { minimum, maximum } = array._zod.computed;
399
- if (minimum !== void 0) {
396
+ const { minimum, maximum } = array._zod.bag;
397
+ if (typeof minimum === "number") {
400
398
  json.minItems = minimum;
401
399
  }
402
- if (maximum !== void 0) {
400
+ if (typeof maximum === "number") {
403
401
  json.maxItems = maximum;
404
402
  }
405
- json.items = this.#handleArrayItemJsonSchema(await this.#convert(array._zod.def.element, options2, lazyDepth2), options2);
403
+ json.items = this.#handleArrayItemJsonSchema(this.#convert(array._zod.def.element, options2, lazyDepth2), options2);
406
404
  return [true, json];
407
405
  }
408
406
  case "object": {
409
407
  const object = schema2;
410
408
  const json = { type: "object" };
411
409
  for (const [key, value] of Object.entries(object._zod.def.shape)) {
412
- const [itemRequired, itemJson] = await this.#convert(value, options2, lazyDepth2);
410
+ const [itemRequired, itemJson] = this.#convert(value, options2, lazyDepth2);
413
411
  json.properties ??= {};
414
412
  json.properties[key] = itemJson;
415
413
  if (itemRequired) {
@@ -421,7 +419,7 @@ class experimental_ZodToJsonSchemaConverter {
421
419
  if (object._zod.def.catchall._zod.def.type === "never") {
422
420
  json.additionalProperties = false;
423
421
  } else {
424
- const [_, addJson] = await this.#convert(object._zod.def.catchall, options2, lazyDepth2);
422
+ const [_, addJson] = this.#convert(object._zod.def.catchall, options2, lazyDepth2);
425
423
  json.additionalProperties = addJson;
426
424
  }
427
425
  }
@@ -432,7 +430,7 @@ class experimental_ZodToJsonSchemaConverter {
432
430
  const anyOf = [];
433
431
  let required = true;
434
432
  for (const item of union._zod.def.options) {
435
- const [itemRequired, itemJson] = await this.#convert(item, options2, lazyDepth2);
433
+ const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2);
436
434
  if (!itemRequired) {
437
435
  required = false;
438
436
  }
@@ -453,7 +451,7 @@ class experimental_ZodToJsonSchemaConverter {
453
451
  const json = { allOf: [] };
454
452
  let required = false;
455
453
  for (const item of [intersection._zod.def.left, intersection._zod.def.right]) {
456
- const [itemRequired, itemJson] = await this.#convert(item, options2, lazyDepth2);
454
+ const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2);
457
455
  json.allOf.push(itemJson);
458
456
  if (itemRequired) {
459
457
  required = true;
@@ -465,16 +463,16 @@ class experimental_ZodToJsonSchemaConverter {
465
463
  const tuple = schema2;
466
464
  const json = { type: "array", prefixItems: [] };
467
465
  for (const item of tuple._zod.def.items) {
468
- json.prefixItems.push(this.#handleArrayItemJsonSchema(await this.#convert(item, options2, lazyDepth2), options2));
466
+ json.prefixItems.push(this.#handleArrayItemJsonSchema(this.#convert(item, options2, lazyDepth2), options2));
469
467
  }
470
468
  if (tuple._zod.def.rest) {
471
- json.items = this.#handleArrayItemJsonSchema(await this.#convert(tuple._zod.def.rest, options2, lazyDepth2), options2);
469
+ json.items = this.#handleArrayItemJsonSchema(this.#convert(tuple._zod.def.rest, options2, lazyDepth2), options2);
472
470
  }
473
- const { minimum, maximum } = tuple._zod.computed;
474
- if (minimum !== void 0) {
471
+ const { minimum, maximum } = tuple._zod.bag;
472
+ if (typeof minimum === "number") {
475
473
  json.minItems = minimum;
476
474
  }
477
- if (maximum !== void 0) {
475
+ if (typeof maximum === "number") {
478
476
  json.maxItems = maximum;
479
477
  }
480
478
  return [true, json];
@@ -482,8 +480,8 @@ class experimental_ZodToJsonSchemaConverter {
482
480
  case "record": {
483
481
  const record = schema2;
484
482
  const json = { type: "object" };
485
- json.propertyNames = (await this.#convert(record._zod.def.keyType, options2, lazyDepth2))[1];
486
- json.additionalProperties = (await this.#convert(record._zod.def.valueType, options2, lazyDepth2))[1];
483
+ json.propertyNames = this.#convert(record._zod.def.keyType, options2, lazyDepth2)[1];
484
+ json.additionalProperties = this.#convert(record._zod.def.valueType, options2, lazyDepth2)[1];
487
485
  return [true, json];
488
486
  }
489
487
  case "map": {
@@ -493,8 +491,8 @@ class experimental_ZodToJsonSchemaConverter {
493
491
  items: {
494
492
  type: "array",
495
493
  prefixItems: [
496
- this.#handleArrayItemJsonSchema(await this.#convert(map._zod.def.keyType, options2, lazyDepth2), options2),
497
- this.#handleArrayItemJsonSchema(await this.#convert(map._zod.def.valueType, options2, lazyDepth2), options2)
494
+ this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.keyType, options2, lazyDepth2), options2),
495
+ this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.valueType, options2, lazyDepth2), options2)
498
496
  ],
499
497
  maxItems: 2,
500
498
  minItems: 2
@@ -506,7 +504,7 @@ class experimental_ZodToJsonSchemaConverter {
506
504
  return [true, {
507
505
  type: "array",
508
506
  uniqueItems: true,
509
- items: this.#handleArrayItemJsonSchema(await this.#convert(set._zod.def.valueType, options2, lazyDepth2), options2)
507
+ items: this.#handleArrayItemJsonSchema(this.#convert(set._zod.def.valueType, options2, lazyDepth2), options2)
510
508
  }];
511
509
  }
512
510
  case "enum": {
@@ -530,12 +528,14 @@ class experimental_ZodToJsonSchemaConverter {
530
528
  case "file": {
531
529
  const file = schema2;
532
530
  const oneOf = [];
533
- const { mime } = file._zod.computed;
534
- for (const type of mime ?? ["*/*"]) {
535
- oneOf.push({
536
- type: "string",
537
- contentMediaType: type
538
- });
531
+ const { mime } = file._zod.bag;
532
+ if (mime === void 0 || Array.isArray(mime) && mime.every((m) => typeof m === "string")) {
533
+ for (const type of mime ?? ["*/*"]) {
534
+ oneOf.push({
535
+ type: "string",
536
+ contentMediaType: type
537
+ });
538
+ }
539
539
  }
540
540
  return [true, oneOf.length === 1 ? oneOf[0] : { anyOf: oneOf }];
541
541
  }
@@ -544,12 +544,12 @@ class experimental_ZodToJsonSchemaConverter {
544
544
  }
545
545
  case "nullable": {
546
546
  const nullable = schema2;
547
- const [required, json] = await this.#convert(nullable._zod.def.innerType, options2, lazyDepth2);
547
+ const [required, json] = this.#convert(nullable._zod.def.innerType, options2, lazyDepth2);
548
548
  return [required, { anyOf: [json, { type: "null" }] }];
549
549
  }
550
550
  case "nonoptional": {
551
551
  const nonoptional = schema2;
552
- const [, json] = await this.#convert(nonoptional._zod.def.innerType, options2, lazyDepth2);
552
+ const [, json] = this.#convert(nonoptional._zod.def.innerType, options2, lazyDepth2);
553
553
  return [true, json];
554
554
  }
555
555
  case "success": {
@@ -558,7 +558,7 @@ class experimental_ZodToJsonSchemaConverter {
558
558
  case "default":
559
559
  case "prefault": {
560
560
  const default_ = schema2;
561
- const [, json] = await this.#convert(default_._zod.def.innerType, options2, lazyDepth2);
561
+ const [, json] = this.#convert(default_._zod.def.innerType, options2, lazyDepth2);
562
562
  return [false, {
563
563
  ...json,
564
564
  default: default_._zod.def.defaultValue
@@ -566,18 +566,18 @@ class experimental_ZodToJsonSchemaConverter {
566
566
  }
567
567
  case "catch": {
568
568
  const catch_ = schema2;
569
- return await this.#convert(catch_._zod.def.innerType, options2, lazyDepth2);
569
+ return this.#convert(catch_._zod.def.innerType, options2, lazyDepth2);
570
570
  }
571
571
  case "nan": {
572
572
  return [true, options2.strategy === "input" ? this.unsupportedJsonSchema : { type: "null" }];
573
573
  }
574
574
  case "pipe": {
575
575
  const pipe = schema2;
576
- return await this.#convert(options2.strategy === "input" ? pipe._zod.def.in : pipe._zod.def.out, options2, lazyDepth2);
576
+ return this.#convert(options2.strategy === "input" ? pipe._zod.def.in : pipe._zod.def.out, options2, lazyDepth2);
577
577
  }
578
578
  case "readonly": {
579
579
  const readonly_ = schema2;
580
- const [required, json] = await this.#convert(readonly_._zod.def.innerType, options2, lazyDepth2);
580
+ const [required, json] = this.#convert(readonly_._zod.def.innerType, options2, lazyDepth2);
581
581
  return [required, { ...json, readOnly: true }];
582
582
  }
583
583
  case "template_literal": {
@@ -589,7 +589,7 @@ class experimental_ZodToJsonSchemaConverter {
589
589
  }
590
590
  case "optional": {
591
591
  const optional = schema2;
592
- const [, json] = await this.#convert(optional._zod.def.innerType, options2, lazyDepth2);
592
+ const [, json] = this.#convert(optional._zod.def.innerType, options2, lazyDepth2);
593
593
  return [false, json];
594
594
  }
595
595
  case "lazy": {
@@ -597,7 +597,7 @@ class experimental_ZodToJsonSchemaConverter {
597
597
  if (lazyDepth2 >= this.maxLazyDepth) {
598
598
  return [false, this.anyJsonSchema];
599
599
  }
600
- return await this.#convert(lazy._zod.def.getter(), options2, lazyDepth2 + 1);
600
+ return this.#convert(lazy._zod.def.getter(), options2, lazyDepth2 + 1);
601
601
  }
602
602
  default: {
603
603
  schema2._zod.def.type;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/zod",
3
3
  "type": "module",
4
- "version": "0.0.0-next.fd13879",
4
+ "version": "0.0.0-next.fd6982a",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -30,17 +30,17 @@
30
30
  ],
31
31
  "peerDependencies": {
32
32
  "zod": ">=3.24.2",
33
- "@orpc/contract": "0.0.0-next.fd13879",
34
- "@orpc/server": "0.0.0-next.fd13879"
33
+ "@orpc/contract": "0.0.0-next.fd6982a",
34
+ "@orpc/server": "0.0.0-next.fd6982a"
35
35
  },
36
36
  "dependencies": {
37
37
  "escape-string-regexp": "^5.0.0",
38
38
  "wildcard-match": "^5.1.3",
39
- "@orpc/openapi": "0.0.0-next.fd13879",
40
- "@orpc/shared": "0.0.0-next.fd13879"
39
+ "@orpc/openapi": "0.0.0-next.fd6982a",
40
+ "@orpc/shared": "0.0.0-next.fd6982a"
41
41
  },
42
42
  "devDependencies": {
43
- "zod": "3.25.0-beta.20250516T005923",
43
+ "zod": "^3.25.11",
44
44
  "zod-to-json-schema": "^3.24.5"
45
45
  },
46
46
  "scripts": {