@orpc/openapi 0.0.0-next.e9dc36e → 0.0.0-next.ee0aeaf

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.js CHANGED
@@ -1,6 +1,11 @@
1
+ import {
2
+ eachContractProcedureLeaf,
3
+ standardizeHTTPPath
4
+ } from "./chunk-7HD5IZWG.js";
5
+
1
6
  // src/generator.ts
2
- import { eachContractRouterLeaf } from "@orpc/contract";
3
- import { toContractRouter } from "@orpc/server";
7
+ import { isContractProcedure } from "@orpc/contract";
8
+ import { LAZY_LOADER_SYMBOL } from "@orpc/server";
4
9
  import { findDeepMatches, isPlainObject, omit } from "@orpc/shared";
5
10
  import { preSerialize } from "@orpc/transformer";
6
11
  import {
@@ -18,7 +23,7 @@ import {
18
23
  Format
19
24
  } from "json-schema-typed/draft-2020-12";
20
25
 
21
- // ../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.mjs
26
+ // ../../node_modules/.pnpm/zod@3.24.1/node_modules/zod/lib/index.mjs
22
27
  var util;
23
28
  (function(util2) {
24
29
  util2.assertEqual = (val) => val;
@@ -169,6 +174,9 @@ var ZodIssueCode = util.arrayToEnum([
169
174
  "not_finite"
170
175
  ]);
171
176
  var ZodError = class _ZodError extends Error {
177
+ get errors() {
178
+ return this.issues;
179
+ }
172
180
  constructor(issues) {
173
181
  super();
174
182
  this.issues = [];
@@ -187,9 +195,6 @@ var ZodError = class _ZodError extends Error {
187
195
  this.name = "ZodError";
188
196
  this.issues = issues;
189
197
  }
190
- get errors() {
191
- return this.issues;
192
- }
193
198
  format(_mapper) {
194
199
  const mapper = _mapper || function(issue) {
195
200
  return issue.message;
@@ -396,8 +401,11 @@ function addIssueToContext(ctx, issueData) {
396
401
  path: ctx.path,
397
402
  errorMaps: [
398
403
  ctx.common.contextualErrorMap,
404
+ // contextual error map is first priority
399
405
  ctx.schemaErrorMap,
406
+ // then schema-bound map if available
400
407
  overrideMap,
408
+ // then global override map
401
409
  overrideMap === errorMap ? void 0 : errorMap
402
410
  // then global default map
403
411
  ].filter((x) => !!x)
@@ -548,34 +556,6 @@ function processCreateParams(params) {
548
556
  return { errorMap: customMap, description };
549
557
  }
550
558
  var ZodType = class {
551
- constructor(def) {
552
- this.spa = this.safeParseAsync;
553
- this._def = def;
554
- this.parse = this.parse.bind(this);
555
- this.safeParse = this.safeParse.bind(this);
556
- this.parseAsync = this.parseAsync.bind(this);
557
- this.safeParseAsync = this.safeParseAsync.bind(this);
558
- this.spa = this.spa.bind(this);
559
- this.refine = this.refine.bind(this);
560
- this.refinement = this.refinement.bind(this);
561
- this.superRefine = this.superRefine.bind(this);
562
- this.optional = this.optional.bind(this);
563
- this.nullable = this.nullable.bind(this);
564
- this.nullish = this.nullish.bind(this);
565
- this.array = this.array.bind(this);
566
- this.promise = this.promise.bind(this);
567
- this.or = this.or.bind(this);
568
- this.and = this.and.bind(this);
569
- this.transform = this.transform.bind(this);
570
- this.brand = this.brand.bind(this);
571
- this.default = this.default.bind(this);
572
- this.catch = this.catch.bind(this);
573
- this.describe = this.describe.bind(this);
574
- this.pipe = this.pipe.bind(this);
575
- this.readonly = this.readonly.bind(this);
576
- this.isNullable = this.isNullable.bind(this);
577
- this.isOptional = this.isOptional.bind(this);
578
- }
579
559
  get description() {
580
560
  return this._def.description;
581
561
  }
@@ -639,6 +619,43 @@ var ZodType = class {
639
619
  const result = this._parseSync({ data, path: ctx.path, parent: ctx });
640
620
  return handleResult(ctx, result);
641
621
  }
622
+ "~validate"(data) {
623
+ var _a, _b;
624
+ const ctx = {
625
+ common: {
626
+ issues: [],
627
+ async: !!this["~standard"].async
628
+ },
629
+ path: [],
630
+ schemaErrorMap: this._def.errorMap,
631
+ parent: null,
632
+ data,
633
+ parsedType: getParsedType(data)
634
+ };
635
+ if (!this["~standard"].async) {
636
+ try {
637
+ const result = this._parseSync({ data, path: [], parent: ctx });
638
+ return isValid(result) ? {
639
+ value: result.value
640
+ } : {
641
+ issues: ctx.common.issues
642
+ };
643
+ } catch (err) {
644
+ if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
645
+ this["~standard"].async = true;
646
+ }
647
+ ctx.common = {
648
+ issues: [],
649
+ async: true
650
+ };
651
+ }
652
+ }
653
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
654
+ value: result.value
655
+ } : {
656
+ issues: ctx.common.issues
657
+ });
658
+ }
642
659
  async parseAsync(data, params) {
643
660
  const result = await this.safeParseAsync(data, params);
644
661
  if (result.success)
@@ -716,6 +733,39 @@ var ZodType = class {
716
733
  superRefine(refinement) {
717
734
  return this._refinement(refinement);
718
735
  }
736
+ constructor(def) {
737
+ this.spa = this.safeParseAsync;
738
+ this._def = def;
739
+ this.parse = this.parse.bind(this);
740
+ this.safeParse = this.safeParse.bind(this);
741
+ this.parseAsync = this.parseAsync.bind(this);
742
+ this.safeParseAsync = this.safeParseAsync.bind(this);
743
+ this.spa = this.spa.bind(this);
744
+ this.refine = this.refine.bind(this);
745
+ this.refinement = this.refinement.bind(this);
746
+ this.superRefine = this.superRefine.bind(this);
747
+ this.optional = this.optional.bind(this);
748
+ this.nullable = this.nullable.bind(this);
749
+ this.nullish = this.nullish.bind(this);
750
+ this.array = this.array.bind(this);
751
+ this.promise = this.promise.bind(this);
752
+ this.or = this.or.bind(this);
753
+ this.and = this.and.bind(this);
754
+ this.transform = this.transform.bind(this);
755
+ this.brand = this.brand.bind(this);
756
+ this.default = this.default.bind(this);
757
+ this.catch = this.catch.bind(this);
758
+ this.describe = this.describe.bind(this);
759
+ this.pipe = this.pipe.bind(this);
760
+ this.readonly = this.readonly.bind(this);
761
+ this.isNullable = this.isNullable.bind(this);
762
+ this.isOptional = this.isOptional.bind(this);
763
+ this["~standard"] = {
764
+ version: 1,
765
+ vendor: "zod",
766
+ validate: (data) => this["~validate"](data)
767
+ };
768
+ }
719
769
  optional() {
720
770
  return ZodOptional.create(this, this._def);
721
771
  }
@@ -726,7 +776,7 @@ var ZodType = class {
726
776
  return this.nullable().optional();
727
777
  }
728
778
  array() {
729
- return ZodArray.create(this, this._def);
779
+ return ZodArray.create(this);
730
780
  }
731
781
  promise() {
732
782
  return ZodPromise.create(this, this._def);
@@ -792,16 +842,20 @@ var ZodType = class {
792
842
  };
793
843
  var cuidRegex = /^c[^\s-]{8,}$/i;
794
844
  var cuid2Regex = /^[0-9a-z]+$/;
795
- var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
845
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
796
846
  var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
797
847
  var nanoidRegex = /^[a-z0-9_-]{21}$/i;
848
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
798
849
  var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
799
850
  var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
800
851
  var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
801
852
  var emojiRegex;
802
853
  var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
803
- var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
854
+ var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
855
+ var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
856
+ var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
804
857
  var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
858
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
805
859
  var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
806
860
  var dateRegex = new RegExp(`^${dateRegexSource}$`);
807
861
  function timeRegexSource(args) {
@@ -834,6 +888,33 @@ function isValidIP(ip, version) {
834
888
  }
835
889
  return false;
836
890
  }
891
+ function isValidJWT(jwt, alg) {
892
+ if (!jwtRegex.test(jwt))
893
+ return false;
894
+ try {
895
+ const [header] = jwt.split(".");
896
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
897
+ const decoded = JSON.parse(atob(base64));
898
+ if (typeof decoded !== "object" || decoded === null)
899
+ return false;
900
+ if (!decoded.typ || !decoded.alg)
901
+ return false;
902
+ if (alg && decoded.alg !== alg)
903
+ return false;
904
+ return true;
905
+ } catch (_a) {
906
+ return false;
907
+ }
908
+ }
909
+ function isValidCidr(ip, version) {
910
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
911
+ return true;
912
+ }
913
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
914
+ return true;
915
+ }
916
+ return false;
917
+ }
837
918
  var ZodString = class _ZodString extends ZodType {
838
919
  _parse(input) {
839
920
  if (this._def.coerce) {
@@ -1090,6 +1171,26 @@ var ZodString = class _ZodString extends ZodType {
1090
1171
  });
1091
1172
  status.dirty();
1092
1173
  }
1174
+ } else if (check.kind === "jwt") {
1175
+ if (!isValidJWT(input.data, check.alg)) {
1176
+ ctx = this._getOrReturnCtx(input, ctx);
1177
+ addIssueToContext(ctx, {
1178
+ validation: "jwt",
1179
+ code: ZodIssueCode.invalid_string,
1180
+ message: check.message
1181
+ });
1182
+ status.dirty();
1183
+ }
1184
+ } else if (check.kind === "cidr") {
1185
+ if (!isValidCidr(input.data, check.version)) {
1186
+ ctx = this._getOrReturnCtx(input, ctx);
1187
+ addIssueToContext(ctx, {
1188
+ validation: "cidr",
1189
+ code: ZodIssueCode.invalid_string,
1190
+ message: check.message
1191
+ });
1192
+ status.dirty();
1193
+ }
1093
1194
  } else if (check.kind === "base64") {
1094
1195
  if (!base64Regex.test(input.data)) {
1095
1196
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1100,6 +1201,16 @@ var ZodString = class _ZodString extends ZodType {
1100
1201
  });
1101
1202
  status.dirty();
1102
1203
  }
1204
+ } else if (check.kind === "base64url") {
1205
+ if (!base64urlRegex.test(input.data)) {
1206
+ ctx = this._getOrReturnCtx(input, ctx);
1207
+ addIssueToContext(ctx, {
1208
+ validation: "base64url",
1209
+ code: ZodIssueCode.invalid_string,
1210
+ message: check.message
1211
+ });
1212
+ status.dirty();
1213
+ }
1103
1214
  } else {
1104
1215
  util.assertNever(check);
1105
1216
  }
@@ -1146,9 +1257,21 @@ var ZodString = class _ZodString extends ZodType {
1146
1257
  base64(message) {
1147
1258
  return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1148
1259
  }
1260
+ base64url(message) {
1261
+ return this._addCheck({
1262
+ kind: "base64url",
1263
+ ...errorUtil.errToObj(message)
1264
+ });
1265
+ }
1266
+ jwt(options) {
1267
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1268
+ }
1149
1269
  ip(options) {
1150
1270
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1151
1271
  }
1272
+ cidr(options) {
1273
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1274
+ }
1152
1275
  datetime(options) {
1153
1276
  var _a, _b;
1154
1277
  if (typeof options === "string") {
@@ -1239,8 +1362,7 @@ var ZodString = class _ZodString extends ZodType {
1239
1362
  });
1240
1363
  }
1241
1364
  /**
1242
- * @deprecated Use z.string().min(1) instead.
1243
- * @see {@link ZodString.min}
1365
+ * Equivalent to `.min(1)`
1244
1366
  */
1245
1367
  nonempty(message) {
1246
1368
  return this.min(1, errorUtil.errToObj(message));
@@ -1302,9 +1424,15 @@ var ZodString = class _ZodString extends ZodType {
1302
1424
  get isIP() {
1303
1425
  return !!this._def.checks.find((ch) => ch.kind === "ip");
1304
1426
  }
1427
+ get isCIDR() {
1428
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1429
+ }
1305
1430
  get isBase64() {
1306
1431
  return !!this._def.checks.find((ch) => ch.kind === "base64");
1307
1432
  }
1433
+ get isBase64url() {
1434
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1435
+ }
1308
1436
  get minLength() {
1309
1437
  let min = null;
1310
1438
  for (const ch of this._def.checks) {
@@ -1582,17 +1710,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1582
1710
  }
1583
1711
  _parse(input) {
1584
1712
  if (this._def.coerce) {
1585
- input.data = BigInt(input.data);
1713
+ try {
1714
+ input.data = BigInt(input.data);
1715
+ } catch (_a) {
1716
+ return this._getInvalidInput(input);
1717
+ }
1586
1718
  }
1587
1719
  const parsedType = this._getType(input);
1588
1720
  if (parsedType !== ZodParsedType.bigint) {
1589
- const ctx2 = this._getOrReturnCtx(input);
1590
- addIssueToContext(ctx2, {
1591
- code: ZodIssueCode.invalid_type,
1592
- expected: ZodParsedType.bigint,
1593
- received: ctx2.parsedType
1594
- });
1595
- return INVALID;
1721
+ return this._getInvalidInput(input);
1596
1722
  }
1597
1723
  let ctx = void 0;
1598
1724
  const status = new ParseStatus();
@@ -1639,6 +1765,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1639
1765
  }
1640
1766
  return { status: status.value, value: input.data };
1641
1767
  }
1768
+ _getInvalidInput(input) {
1769
+ const ctx = this._getOrReturnCtx(input);
1770
+ addIssueToContext(ctx, {
1771
+ code: ZodIssueCode.invalid_type,
1772
+ expected: ZodParsedType.bigint,
1773
+ received: ctx.parsedType
1774
+ });
1775
+ return INVALID;
1776
+ }
1642
1777
  gte(value, message) {
1643
1778
  return this.setLimit("min", value, true, errorUtil.toString(message));
1644
1779
  }
@@ -3809,10 +3944,15 @@ var NON_LOGIC_KEYWORDS = [
3809
3944
  var UNSUPPORTED_JSON_SCHEMA = { not: {} };
3810
3945
  var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
3811
3946
  function zodToJsonSchema(schema, options) {
3947
+ if (schema["~standard"].vendor !== "zod") {
3948
+ console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
3949
+ return {};
3950
+ }
3951
+ const schema__ = schema;
3812
3952
  if (!options?.isHandledCustomJSONSchema) {
3813
- const customJSONSchema = getCustomJSONSchema(schema._def, options);
3953
+ const customJSONSchema = getCustomJSONSchema(schema__._def, options);
3814
3954
  if (customJSONSchema) {
3815
- const json = zodToJsonSchema(schema, {
3955
+ const json = zodToJsonSchema(schema__, {
3816
3956
  ...options,
3817
3957
  isHandledCustomJSONSchema: true
3818
3958
  });
@@ -3823,13 +3963,13 @@ function zodToJsonSchema(schema, options) {
3823
3963
  }
3824
3964
  }
3825
3965
  const childOptions = { ...options, isHandledCustomJSONSchema: false };
3826
- const customType = getCustomZodType(schema._def);
3966
+ const customType = getCustomZodType(schema__._def);
3827
3967
  switch (customType) {
3828
3968
  case "Blob": {
3829
3969
  return { type: "string", contentMediaType: "*/*" };
3830
3970
  }
3831
3971
  case "File": {
3832
- const mimeType = getCustomZodFileMimeType(schema._def) ?? "*/*";
3972
+ const mimeType = getCustomZodFileMimeType(schema__._def) ?? "*/*";
3833
3973
  return { type: "string", contentMediaType: mimeType };
3834
3974
  }
3835
3975
  case "Invalid Date": {
@@ -3846,10 +3986,10 @@ function zodToJsonSchema(schema, options) {
3846
3986
  }
3847
3987
  }
3848
3988
  const _expectedCustomType = customType;
3849
- const typeName = schema._def.typeName;
3989
+ const typeName = schema__._def.typeName;
3850
3990
  switch (typeName) {
3851
3991
  case ZodFirstPartyTypeKind.ZodString: {
3852
- const schema_ = schema;
3992
+ const schema_ = schema__;
3853
3993
  const json = { type: "string" };
3854
3994
  for (const check of schema_._def.checks) {
3855
3995
  switch (check.kind) {
@@ -3917,6 +4057,12 @@ function zodToJsonSchema(schema, options) {
3917
4057
  case "ip":
3918
4058
  json.format = Format.IPv4;
3919
4059
  break;
4060
+ case "jwt":
4061
+ json.pattern = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$";
4062
+ break;
4063
+ case "base64url":
4064
+ json.pattern = "^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$";
4065
+ break;
3920
4066
  default: {
3921
4067
  const _expect = check.kind;
3922
4068
  }
@@ -3925,7 +4071,7 @@ function zodToJsonSchema(schema, options) {
3925
4071
  return json;
3926
4072
  }
3927
4073
  case ZodFirstPartyTypeKind.ZodNumber: {
3928
- const schema_ = schema;
4074
+ const schema_ = schema__;
3929
4075
  const json = { type: "number" };
3930
4076
  for (const check of schema_._def.checks) {
3931
4077
  switch (check.kind) {
@@ -3970,23 +4116,23 @@ function zodToJsonSchema(schema, options) {
3970
4116
  return UNDEFINED_JSON_SCHEMA;
3971
4117
  }
3972
4118
  case ZodFirstPartyTypeKind.ZodLiteral: {
3973
- const schema_ = schema;
4119
+ const schema_ = schema__;
3974
4120
  return { const: schema_._def.value };
3975
4121
  }
3976
4122
  case ZodFirstPartyTypeKind.ZodEnum: {
3977
- const schema_ = schema;
4123
+ const schema_ = schema__;
3978
4124
  return {
3979
4125
  enum: schema_._def.values
3980
4126
  };
3981
4127
  }
3982
4128
  case ZodFirstPartyTypeKind.ZodNativeEnum: {
3983
- const schema_ = schema;
4129
+ const schema_ = schema__;
3984
4130
  return {
3985
4131
  enum: Object.values(schema_._def.values)
3986
4132
  };
3987
4133
  }
3988
4134
  case ZodFirstPartyTypeKind.ZodArray: {
3989
- const schema_ = schema;
4135
+ const schema_ = schema__;
3990
4136
  const def = schema_._def;
3991
4137
  const json = { type: "array" };
3992
4138
  if (def.exactLength) {
@@ -4002,7 +4148,7 @@ function zodToJsonSchema(schema, options) {
4002
4148
  return json;
4003
4149
  }
4004
4150
  case ZodFirstPartyTypeKind.ZodTuple: {
4005
- const schema_ = schema;
4151
+ const schema_ = schema__;
4006
4152
  const prefixItems = [];
4007
4153
  const json = { type: "array" };
4008
4154
  for (const item of schema_._def.items) {
@@ -4020,7 +4166,7 @@ function zodToJsonSchema(schema, options) {
4020
4166
  return json;
4021
4167
  }
4022
4168
  case ZodFirstPartyTypeKind.ZodObject: {
4023
- const schema_ = schema;
4169
+ const schema_ = schema__;
4024
4170
  const json = { type: "object" };
4025
4171
  const properties = {};
4026
4172
  const required = [];
@@ -4056,7 +4202,7 @@ function zodToJsonSchema(schema, options) {
4056
4202
  return json;
4057
4203
  }
4058
4204
  case ZodFirstPartyTypeKind.ZodRecord: {
4059
- const schema_ = schema;
4205
+ const schema_ = schema__;
4060
4206
  const json = { type: "object" };
4061
4207
  json.additionalProperties = zodToJsonSchema(
4062
4208
  schema_._def.valueType,
@@ -4065,14 +4211,14 @@ function zodToJsonSchema(schema, options) {
4065
4211
  return json;
4066
4212
  }
4067
4213
  case ZodFirstPartyTypeKind.ZodSet: {
4068
- const schema_ = schema;
4214
+ const schema_ = schema__;
4069
4215
  return {
4070
4216
  type: "array",
4071
4217
  items: zodToJsonSchema(schema_._def.valueType, childOptions)
4072
4218
  };
4073
4219
  }
4074
4220
  case ZodFirstPartyTypeKind.ZodMap: {
4075
- const schema_ = schema;
4221
+ const schema_ = schema__;
4076
4222
  return {
4077
4223
  type: "array",
4078
4224
  items: {
@@ -4088,7 +4234,7 @@ function zodToJsonSchema(schema, options) {
4088
4234
  }
4089
4235
  case ZodFirstPartyTypeKind.ZodUnion:
4090
4236
  case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
4091
- const schema_ = schema;
4237
+ const schema_ = schema__;
4092
4238
  const anyOf = [];
4093
4239
  for (const s of schema_._def.options) {
4094
4240
  anyOf.push(zodToJsonSchema(s, childOptions));
@@ -4096,7 +4242,7 @@ function zodToJsonSchema(schema, options) {
4096
4242
  return { anyOf };
4097
4243
  }
4098
4244
  case ZodFirstPartyTypeKind.ZodIntersection: {
4099
- const schema_ = schema;
4245
+ const schema_ = schema__;
4100
4246
  const allOf = [];
4101
4247
  for (const s of [schema_._def.left, schema_._def.right]) {
4102
4248
  allOf.push(zodToJsonSchema(s, childOptions));
@@ -4104,7 +4250,7 @@ function zodToJsonSchema(schema, options) {
4104
4250
  return { allOf };
4105
4251
  }
4106
4252
  case ZodFirstPartyTypeKind.ZodLazy: {
4107
- const schema_ = schema;
4253
+ const schema_ = schema__;
4108
4254
  const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
4109
4255
  const lazyDepth = childOptions?.lazyDepth ?? 0;
4110
4256
  if (lazyDepth > maxLazyDepth) {
@@ -4121,44 +4267,44 @@ function zodToJsonSchema(schema, options) {
4121
4267
  return {};
4122
4268
  }
4123
4269
  case ZodFirstPartyTypeKind.ZodOptional: {
4124
- const schema_ = schema;
4270
+ const schema_ = schema__;
4125
4271
  const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
4126
4272
  return {
4127
4273
  anyOf: [UNDEFINED_JSON_SCHEMA, inner]
4128
4274
  };
4129
4275
  }
4130
4276
  case ZodFirstPartyTypeKind.ZodReadonly: {
4131
- const schema_ = schema;
4277
+ const schema_ = schema__;
4132
4278
  return zodToJsonSchema(schema_._def.innerType, childOptions);
4133
4279
  }
4134
4280
  case ZodFirstPartyTypeKind.ZodDefault: {
4135
- const schema_ = schema;
4281
+ const schema_ = schema__;
4136
4282
  return zodToJsonSchema(schema_._def.innerType, childOptions);
4137
4283
  }
4138
4284
  case ZodFirstPartyTypeKind.ZodEffects: {
4139
- const schema_ = schema;
4285
+ const schema_ = schema__;
4140
4286
  if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
4141
4287
  return {};
4142
4288
  }
4143
4289
  return zodToJsonSchema(schema_._def.schema, childOptions);
4144
4290
  }
4145
4291
  case ZodFirstPartyTypeKind.ZodCatch: {
4146
- const schema_ = schema;
4292
+ const schema_ = schema__;
4147
4293
  return zodToJsonSchema(schema_._def.innerType, childOptions);
4148
4294
  }
4149
4295
  case ZodFirstPartyTypeKind.ZodBranded: {
4150
- const schema_ = schema;
4296
+ const schema_ = schema__;
4151
4297
  return zodToJsonSchema(schema_._def.type, childOptions);
4152
4298
  }
4153
4299
  case ZodFirstPartyTypeKind.ZodPipeline: {
4154
- const schema_ = schema;
4300
+ const schema_ = schema__;
4155
4301
  return zodToJsonSchema(
4156
4302
  childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
4157
4303
  childOptions
4158
4304
  );
4159
4305
  }
4160
4306
  case ZodFirstPartyTypeKind.ZodNullable: {
4161
- const schema_ = schema;
4307
+ const schema_ = schema__;
4162
4308
  const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
4163
4309
  return {
4164
4310
  anyOf: [{ type: "null" }, inner]
@@ -4210,7 +4356,7 @@ function extractJSONSchema(schema, check, matches = []) {
4210
4356
  }
4211
4357
 
4212
4358
  // src/generator.ts
4213
- function generateOpenAPI(opts, options) {
4359
+ async function generateOpenAPI(opts, options) {
4214
4360
  const throwOnMissingTagDefinition = options?.throwOnMissingTagDefinition ?? false;
4215
4361
  const ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
4216
4362
  const builder = new OpenApiBuilder({
@@ -4218,197 +4364,214 @@ function generateOpenAPI(opts, options) {
4218
4364
  openapi: "3.1.0"
4219
4365
  });
4220
4366
  const rootTags = opts.tags?.map((tag) => tag.name) ?? [];
4221
- const router = toContractRouter(opts.router);
4222
- eachContractRouterLeaf(router, (procedure, path_) => {
4223
- const internal = procedure.zz$cp;
4224
- if (ignoreUndefinedPathProcedures && internal.path === void 0) {
4225
- return;
4226
- }
4227
- const path = internal.path ?? `/${path_.map(encodeURIComponent).join("/")}`;
4228
- const method = internal.method ?? "POST";
4229
- let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
4230
- const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
4231
- const params = (() => {
4232
- const names = path.match(/\{([^}]+)\}/g);
4233
- if (!names || !names.length) {
4234
- return void 0;
4367
+ const pending = [{
4368
+ path: [],
4369
+ router: opts.router
4370
+ }];
4371
+ for (const item of pending) {
4372
+ const lazies = eachContractProcedureLeaf(item, ({ contract, path }) => {
4373
+ if (!isContractProcedure(contract)) {
4374
+ return;
4235
4375
  }
4236
- if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
4237
- throw new Error(
4238
- `When path has parameters, input schema must be an object [${path_.join(".")}]`
4239
- );
4376
+ const internal = contract["~orpc"];
4377
+ if (ignoreUndefinedPathProcedures && internal.route?.path === void 0) {
4378
+ return;
4240
4379
  }
4241
- return names.map((raw) => raw.slice(1, -1)).map((name) => {
4242
- let schema = inputSchema.properties?.[name];
4243
- const required = inputSchema.required?.includes(name);
4244
- if (schema === void 0) {
4245
- throw new Error(
4246
- `Parameter ${name} is missing in input schema [${path_.join(".")}]`
4247
- );
4380
+ const httpPath = internal.route?.path ? standardizeHTTPPath(internal.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
4381
+ const method = internal.route?.method ?? "POST";
4382
+ let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
4383
+ const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
4384
+ const params = (() => {
4385
+ const names = httpPath.match(/\{([^}]+)\}/g);
4386
+ if (!names || !names.length) {
4387
+ return void 0;
4248
4388
  }
4249
- if (!required) {
4389
+ if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
4250
4390
  throw new Error(
4251
- `Parameter ${name} must be required in input schema [${path_.join(".")}]`
4391
+ `When path has parameters, input schema must be an object [${path.join(".")}]`
4252
4392
  );
4253
4393
  }
4254
- const examples = inputSchema.examples?.filter((example) => {
4255
- return isPlainObject(example) && name in example;
4256
- }).map((example) => {
4257
- return example[name];
4258
- });
4259
- schema = {
4260
- examples: examples?.length ? examples : void 0,
4261
- ...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
4262
- };
4263
- inputSchema = {
4264
- ...inputSchema,
4265
- properties: inputSchema.properties ? Object.entries(inputSchema.properties).reduce(
4266
- (acc, [key, value]) => {
4267
- if (key !== name) {
4268
- acc[key] = value;
4269
- }
4270
- return acc;
4271
- },
4272
- {}
4273
- ) : void 0,
4274
- required: inputSchema.required?.filter((v) => v !== name),
4275
- examples: inputSchema.examples?.map((example) => {
4276
- if (!isPlainObject(example))
4277
- return example;
4278
- return Object.entries(example).reduce(
4279
- (acc, [key, value]) => {
4280
- if (key !== name) {
4281
- acc[key] = value;
4282
- }
4283
- return acc;
4284
- },
4285
- {}
4394
+ return names.map((raw) => raw.slice(1, -1)).map((name) => {
4395
+ let schema = inputSchema.properties?.[name];
4396
+ const required = inputSchema.required?.includes(name);
4397
+ if (schema === void 0) {
4398
+ throw new Error(
4399
+ `Parameter ${name} is missing in input schema [${path.join(".")}]`
4286
4400
  );
4287
- })
4288
- };
4289
- return {
4290
- name,
4291
- in: "path",
4292
- required: true,
4293
- schema,
4294
- example: internal.inputExample?.[name]
4295
- };
4296
- });
4297
- })();
4298
- const query = (() => {
4299
- if (method !== "GET" || Object.keys(inputSchema).length === 0) {
4300
- return void 0;
4301
- }
4302
- if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
4303
- throw new Error(
4304
- `When method is GET, input schema must be an object [${path_.join(".")}]`
4305
- );
4306
- }
4307
- return Object.entries(inputSchema.properties ?? {}).map(
4308
- ([name, schema]) => {
4401
+ }
4402
+ if (!required) {
4403
+ throw new Error(
4404
+ `Parameter ${name} must be required in input schema [${path.join(".")}]`
4405
+ );
4406
+ }
4309
4407
  const examples = inputSchema.examples?.filter((example) => {
4310
4408
  return isPlainObject(example) && name in example;
4311
4409
  }).map((example) => {
4312
4410
  return example[name];
4313
4411
  });
4314
- const schema_ = {
4412
+ schema = {
4315
4413
  examples: examples?.length ? examples : void 0,
4316
4414
  ...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
4317
4415
  };
4416
+ inputSchema = {
4417
+ ...inputSchema,
4418
+ properties: inputSchema.properties ? Object.entries(inputSchema.properties).reduce(
4419
+ (acc, [key, value]) => {
4420
+ if (key !== name) {
4421
+ acc[key] = value;
4422
+ }
4423
+ return acc;
4424
+ },
4425
+ {}
4426
+ ) : void 0,
4427
+ required: inputSchema.required?.filter((v) => v !== name),
4428
+ examples: inputSchema.examples?.map((example) => {
4429
+ if (!isPlainObject(example))
4430
+ return example;
4431
+ return Object.entries(example).reduce(
4432
+ (acc, [key, value]) => {
4433
+ if (key !== name) {
4434
+ acc[key] = value;
4435
+ }
4436
+ return acc;
4437
+ },
4438
+ {}
4439
+ );
4440
+ })
4441
+ };
4318
4442
  return {
4319
4443
  name,
4320
- in: "query",
4321
- style: "deepObject",
4322
- required: inputSchema?.required?.includes(name) ?? false,
4323
- schema: schema_,
4444
+ in: "path",
4445
+ required: true,
4446
+ schema,
4324
4447
  example: internal.inputExample?.[name]
4325
4448
  };
4449
+ });
4450
+ })();
4451
+ const query = (() => {
4452
+ if (method !== "GET" || Object.keys(inputSchema).length === 0) {
4453
+ return void 0;
4326
4454
  }
4327
- );
4328
- })();
4329
- const parameters = [...params ?? [], ...query ?? []];
4330
- const requestBody = (() => {
4331
- if (method === "GET") {
4332
- return void 0;
4333
- }
4334
- const { schema, matches } = extractJSONSchema(inputSchema, isFileSchema);
4335
- const files = matches;
4336
- const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
4337
- if (files.length) {
4338
- parameters.push({
4339
- name: "content-disposition",
4340
- in: "header",
4341
- required: schema === void 0,
4342
- schema: {
4343
- type: "string",
4344
- pattern: "filename",
4345
- example: 'filename="file.png"',
4346
- description: "To define the file name. Required when the request body is a file."
4455
+ if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
4456
+ throw new Error(
4457
+ `When method is GET, input schema must be an object [${path.join(".")}]`
4458
+ );
4459
+ }
4460
+ return Object.entries(inputSchema.properties ?? {}).map(
4461
+ ([name, schema]) => {
4462
+ const examples = inputSchema.examples?.filter((example) => {
4463
+ return isPlainObject(example) && name in example;
4464
+ }).map((example) => {
4465
+ return example[name];
4466
+ });
4467
+ const schema_ = {
4468
+ examples: examples?.length ? examples : void 0,
4469
+ ...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
4470
+ };
4471
+ return {
4472
+ name,
4473
+ in: "query",
4474
+ style: "deepObject",
4475
+ required: inputSchema?.required?.includes(name) ?? false,
4476
+ schema: schema_,
4477
+ example: internal.inputExample?.[name]
4478
+ };
4347
4479
  }
4348
- });
4349
- }
4350
- const content = {};
4351
- for (const file of files) {
4352
- content[file.contentMediaType] = {
4353
- schema: file
4354
- };
4355
- }
4356
- if (schema !== void 0) {
4357
- content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
4358
- schema,
4359
- example: internal.inputExample
4360
- };
4361
- }
4362
- return {
4363
- required: Boolean(internal.InputSchema?.isOptional()),
4364
- content
4365
- };
4366
- })();
4367
- const successResponse = (() => {
4368
- const { schema, matches } = extractJSONSchema(outputSchema, isFileSchema);
4369
- const files = matches;
4370
- const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
4371
- const content = {};
4372
- for (const file of files) {
4373
- content[file.contentMediaType] = {
4374
- schema: file
4480
+ );
4481
+ })();
4482
+ const parameters = [...params ?? [], ...query ?? []];
4483
+ const requestBody = (() => {
4484
+ if (method === "GET") {
4485
+ return void 0;
4486
+ }
4487
+ const { schema, matches } = extractJSONSchema(inputSchema, isFileSchema);
4488
+ const files = matches;
4489
+ const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
4490
+ if (files.length) {
4491
+ parameters.push({
4492
+ name: "content-disposition",
4493
+ in: "header",
4494
+ required: schema === void 0,
4495
+ schema: {
4496
+ type: "string",
4497
+ pattern: "filename",
4498
+ example: 'filename="file.png"',
4499
+ description: "To define the file name. Required when the request body is a file."
4500
+ }
4501
+ });
4502
+ }
4503
+ const content = {};
4504
+ for (const file of files) {
4505
+ content[file.contentMediaType] = {
4506
+ schema: file
4507
+ };
4508
+ }
4509
+ if (schema !== void 0) {
4510
+ content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
4511
+ schema,
4512
+ example: internal.inputExample
4513
+ };
4514
+ }
4515
+ return {
4516
+ required: Boolean(
4517
+ internal.InputSchema && "isOptional" in internal.InputSchema && typeof internal.InputSchema.isOptional === "function" ? internal.InputSchema.isOptional() : false
4518
+ ),
4519
+ content
4375
4520
  };
4376
- }
4377
- if (schema !== void 0) {
4378
- content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
4379
- schema,
4380
- example: internal.outputExample
4521
+ })();
4522
+ const successResponse = (() => {
4523
+ const { schema, matches } = extractJSONSchema(outputSchema, isFileSchema);
4524
+ const files = matches;
4525
+ const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
4526
+ const content = {};
4527
+ for (const file of files) {
4528
+ content[file.contentMediaType] = {
4529
+ schema: file
4530
+ };
4531
+ }
4532
+ if (schema !== void 0) {
4533
+ content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
4534
+ schema,
4535
+ example: internal.outputExample
4536
+ };
4537
+ }
4538
+ return {
4539
+ description: "OK",
4540
+ content
4381
4541
  };
4542
+ })();
4543
+ if (throwOnMissingTagDefinition && internal.route?.tags) {
4544
+ const missingTag = internal.route?.tags.find((tag) => !rootTags.includes(tag));
4545
+ if (missingTag !== void 0) {
4546
+ throw new Error(
4547
+ `Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path.join(".")}]`
4548
+ );
4549
+ }
4382
4550
  }
4383
- return {
4384
- description: "OK",
4385
- content
4551
+ const operation = {
4552
+ summary: internal.route?.summary,
4553
+ description: internal.route?.description,
4554
+ deprecated: internal.route?.deprecated,
4555
+ tags: internal.route?.tags,
4556
+ operationId: path.join("."),
4557
+ parameters: parameters.length ? parameters : void 0,
4558
+ requestBody,
4559
+ responses: {
4560
+ 200: successResponse
4561
+ }
4386
4562
  };
4387
- })();
4388
- if (throwOnMissingTagDefinition && internal.tags) {
4389
- const missingTag = internal.tags.find((tag) => !rootTags.includes(tag));
4390
- if (missingTag !== void 0) {
4391
- throw new Error(
4392
- `Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path_.join(".")}]`
4393
- );
4394
- }
4395
- }
4396
- const operation = {
4397
- summary: internal.summary,
4398
- description: internal.description,
4399
- deprecated: internal.deprecated,
4400
- tags: internal.tags,
4401
- operationId: path_.join("."),
4402
- parameters: parameters.length ? parameters : void 0,
4403
- requestBody,
4404
- responses: {
4405
- 200: successResponse
4406
- }
4407
- };
4408
- builder.addPath(path, {
4409
- [method.toLocaleLowerCase()]: operation
4563
+ builder.addPath(httpPath, {
4564
+ [method.toLocaleLowerCase()]: operation
4565
+ });
4410
4566
  });
4411
- });
4567
+ for (const lazy of lazies) {
4568
+ const router = (await lazy.lazy[LAZY_LOADER_SYMBOL]()).default;
4569
+ pending.push({
4570
+ path: lazy.path,
4571
+ router
4572
+ });
4573
+ }
4574
+ }
4412
4575
  return preSerialize(builder.getSpec());
4413
4576
  }
4414
4577
  function isFileSchema(schema) {