@orpc/openapi 0.0.0-next.1d55ec0 → 0.0.0-next.2f8ca7f
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/chunk-KZIT2WCV.js +49 -0
- package/dist/fetch.js +708 -0
- package/dist/index.js +363 -213
- package/dist/src/fetch/base-handler.d.ts +15 -0
- package/dist/src/fetch/index.d.ts +4 -0
- package/dist/src/fetch/server-handler.d.ts +3 -0
- package/dist/src/fetch/serverless-handler.d.ts +3 -0
- package/dist/src/generator.d.ts +2 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/utils.d.ts +16 -0
- package/dist/src/zod-to-json-schema.d.ts +1 -0
- package/package.json +15 -8
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
eachContractProcedureLeaf
|
|
3
|
+
} from "./chunk-KZIT2WCV.js";
|
|
4
|
+
|
|
1
5
|
// src/generator.ts
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
6
|
+
import { isContractProcedure } from "@orpc/contract";
|
|
7
|
+
import { LAZY_LOADER_SYMBOL } from "@orpc/server";
|
|
4
8
|
import { findDeepMatches, isPlainObject, omit } from "@orpc/shared";
|
|
5
9
|
import { preSerialize } from "@orpc/transformer";
|
|
6
10
|
import {
|
|
@@ -18,7 +22,7 @@ import {
|
|
|
18
22
|
Format
|
|
19
23
|
} from "json-schema-typed/draft-2020-12";
|
|
20
24
|
|
|
21
|
-
// ../../node_modules/.pnpm/zod@3.
|
|
25
|
+
// ../../node_modules/.pnpm/zod@3.24.1/node_modules/zod/lib/index.mjs
|
|
22
26
|
var util;
|
|
23
27
|
(function(util2) {
|
|
24
28
|
util2.assertEqual = (val) => val;
|
|
@@ -169,6 +173,9 @@ var ZodIssueCode = util.arrayToEnum([
|
|
|
169
173
|
"not_finite"
|
|
170
174
|
]);
|
|
171
175
|
var ZodError = class _ZodError extends Error {
|
|
176
|
+
get errors() {
|
|
177
|
+
return this.issues;
|
|
178
|
+
}
|
|
172
179
|
constructor(issues) {
|
|
173
180
|
super();
|
|
174
181
|
this.issues = [];
|
|
@@ -187,9 +194,6 @@ var ZodError = class _ZodError extends Error {
|
|
|
187
194
|
this.name = "ZodError";
|
|
188
195
|
this.issues = issues;
|
|
189
196
|
}
|
|
190
|
-
get errors() {
|
|
191
|
-
return this.issues;
|
|
192
|
-
}
|
|
193
197
|
format(_mapper) {
|
|
194
198
|
const mapper = _mapper || function(issue) {
|
|
195
199
|
return issue.message;
|
|
@@ -396,8 +400,11 @@ function addIssueToContext(ctx, issueData) {
|
|
|
396
400
|
path: ctx.path,
|
|
397
401
|
errorMaps: [
|
|
398
402
|
ctx.common.contextualErrorMap,
|
|
403
|
+
// contextual error map is first priority
|
|
399
404
|
ctx.schemaErrorMap,
|
|
405
|
+
// then schema-bound map if available
|
|
400
406
|
overrideMap,
|
|
407
|
+
// then global override map
|
|
401
408
|
overrideMap === errorMap ? void 0 : errorMap
|
|
402
409
|
// then global default map
|
|
403
410
|
].filter((x) => !!x)
|
|
@@ -548,34 +555,6 @@ function processCreateParams(params) {
|
|
|
548
555
|
return { errorMap: customMap, description };
|
|
549
556
|
}
|
|
550
557
|
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
558
|
get description() {
|
|
580
559
|
return this._def.description;
|
|
581
560
|
}
|
|
@@ -639,6 +618,43 @@ var ZodType = class {
|
|
|
639
618
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
640
619
|
return handleResult(ctx, result);
|
|
641
620
|
}
|
|
621
|
+
"~validate"(data) {
|
|
622
|
+
var _a, _b;
|
|
623
|
+
const ctx = {
|
|
624
|
+
common: {
|
|
625
|
+
issues: [],
|
|
626
|
+
async: !!this["~standard"].async
|
|
627
|
+
},
|
|
628
|
+
path: [],
|
|
629
|
+
schemaErrorMap: this._def.errorMap,
|
|
630
|
+
parent: null,
|
|
631
|
+
data,
|
|
632
|
+
parsedType: getParsedType(data)
|
|
633
|
+
};
|
|
634
|
+
if (!this["~standard"].async) {
|
|
635
|
+
try {
|
|
636
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
637
|
+
return isValid(result) ? {
|
|
638
|
+
value: result.value
|
|
639
|
+
} : {
|
|
640
|
+
issues: ctx.common.issues
|
|
641
|
+
};
|
|
642
|
+
} catch (err) {
|
|
643
|
+
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")) {
|
|
644
|
+
this["~standard"].async = true;
|
|
645
|
+
}
|
|
646
|
+
ctx.common = {
|
|
647
|
+
issues: [],
|
|
648
|
+
async: true
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
653
|
+
value: result.value
|
|
654
|
+
} : {
|
|
655
|
+
issues: ctx.common.issues
|
|
656
|
+
});
|
|
657
|
+
}
|
|
642
658
|
async parseAsync(data, params) {
|
|
643
659
|
const result = await this.safeParseAsync(data, params);
|
|
644
660
|
if (result.success)
|
|
@@ -716,6 +732,39 @@ var ZodType = class {
|
|
|
716
732
|
superRefine(refinement) {
|
|
717
733
|
return this._refinement(refinement);
|
|
718
734
|
}
|
|
735
|
+
constructor(def) {
|
|
736
|
+
this.spa = this.safeParseAsync;
|
|
737
|
+
this._def = def;
|
|
738
|
+
this.parse = this.parse.bind(this);
|
|
739
|
+
this.safeParse = this.safeParse.bind(this);
|
|
740
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
741
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
742
|
+
this.spa = this.spa.bind(this);
|
|
743
|
+
this.refine = this.refine.bind(this);
|
|
744
|
+
this.refinement = this.refinement.bind(this);
|
|
745
|
+
this.superRefine = this.superRefine.bind(this);
|
|
746
|
+
this.optional = this.optional.bind(this);
|
|
747
|
+
this.nullable = this.nullable.bind(this);
|
|
748
|
+
this.nullish = this.nullish.bind(this);
|
|
749
|
+
this.array = this.array.bind(this);
|
|
750
|
+
this.promise = this.promise.bind(this);
|
|
751
|
+
this.or = this.or.bind(this);
|
|
752
|
+
this.and = this.and.bind(this);
|
|
753
|
+
this.transform = this.transform.bind(this);
|
|
754
|
+
this.brand = this.brand.bind(this);
|
|
755
|
+
this.default = this.default.bind(this);
|
|
756
|
+
this.catch = this.catch.bind(this);
|
|
757
|
+
this.describe = this.describe.bind(this);
|
|
758
|
+
this.pipe = this.pipe.bind(this);
|
|
759
|
+
this.readonly = this.readonly.bind(this);
|
|
760
|
+
this.isNullable = this.isNullable.bind(this);
|
|
761
|
+
this.isOptional = this.isOptional.bind(this);
|
|
762
|
+
this["~standard"] = {
|
|
763
|
+
version: 1,
|
|
764
|
+
vendor: "zod",
|
|
765
|
+
validate: (data) => this["~validate"](data)
|
|
766
|
+
};
|
|
767
|
+
}
|
|
719
768
|
optional() {
|
|
720
769
|
return ZodOptional.create(this, this._def);
|
|
721
770
|
}
|
|
@@ -726,7 +775,7 @@ var ZodType = class {
|
|
|
726
775
|
return this.nullable().optional();
|
|
727
776
|
}
|
|
728
777
|
array() {
|
|
729
|
-
return ZodArray.create(this
|
|
778
|
+
return ZodArray.create(this);
|
|
730
779
|
}
|
|
731
780
|
promise() {
|
|
732
781
|
return ZodPromise.create(this, this._def);
|
|
@@ -792,16 +841,20 @@ var ZodType = class {
|
|
|
792
841
|
};
|
|
793
842
|
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
794
843
|
var cuid2Regex = /^[0-9a-z]+$/;
|
|
795
|
-
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}
|
|
844
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
796
845
|
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
846
|
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
847
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
798
848
|
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
849
|
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
800
850
|
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
801
851
|
var emojiRegex;
|
|
802
852
|
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
|
|
853
|
+
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])$/;
|
|
854
|
+
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]))$/;
|
|
855
|
+
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
856
|
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
857
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
805
858
|
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
859
|
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
807
860
|
function timeRegexSource(args) {
|
|
@@ -834,6 +887,33 @@ function isValidIP(ip, version) {
|
|
|
834
887
|
}
|
|
835
888
|
return false;
|
|
836
889
|
}
|
|
890
|
+
function isValidJWT(jwt, alg) {
|
|
891
|
+
if (!jwtRegex.test(jwt))
|
|
892
|
+
return false;
|
|
893
|
+
try {
|
|
894
|
+
const [header] = jwt.split(".");
|
|
895
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
896
|
+
const decoded = JSON.parse(atob(base64));
|
|
897
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
898
|
+
return false;
|
|
899
|
+
if (!decoded.typ || !decoded.alg)
|
|
900
|
+
return false;
|
|
901
|
+
if (alg && decoded.alg !== alg)
|
|
902
|
+
return false;
|
|
903
|
+
return true;
|
|
904
|
+
} catch (_a) {
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
function isValidCidr(ip, version) {
|
|
909
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
910
|
+
return true;
|
|
911
|
+
}
|
|
912
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
913
|
+
return true;
|
|
914
|
+
}
|
|
915
|
+
return false;
|
|
916
|
+
}
|
|
837
917
|
var ZodString = class _ZodString extends ZodType {
|
|
838
918
|
_parse(input) {
|
|
839
919
|
if (this._def.coerce) {
|
|
@@ -1090,6 +1170,26 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1090
1170
|
});
|
|
1091
1171
|
status.dirty();
|
|
1092
1172
|
}
|
|
1173
|
+
} else if (check.kind === "jwt") {
|
|
1174
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1175
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1176
|
+
addIssueToContext(ctx, {
|
|
1177
|
+
validation: "jwt",
|
|
1178
|
+
code: ZodIssueCode.invalid_string,
|
|
1179
|
+
message: check.message
|
|
1180
|
+
});
|
|
1181
|
+
status.dirty();
|
|
1182
|
+
}
|
|
1183
|
+
} else if (check.kind === "cidr") {
|
|
1184
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1185
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1186
|
+
addIssueToContext(ctx, {
|
|
1187
|
+
validation: "cidr",
|
|
1188
|
+
code: ZodIssueCode.invalid_string,
|
|
1189
|
+
message: check.message
|
|
1190
|
+
});
|
|
1191
|
+
status.dirty();
|
|
1192
|
+
}
|
|
1093
1193
|
} else if (check.kind === "base64") {
|
|
1094
1194
|
if (!base64Regex.test(input.data)) {
|
|
1095
1195
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1100,6 +1200,16 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1100
1200
|
});
|
|
1101
1201
|
status.dirty();
|
|
1102
1202
|
}
|
|
1203
|
+
} else if (check.kind === "base64url") {
|
|
1204
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1205
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1206
|
+
addIssueToContext(ctx, {
|
|
1207
|
+
validation: "base64url",
|
|
1208
|
+
code: ZodIssueCode.invalid_string,
|
|
1209
|
+
message: check.message
|
|
1210
|
+
});
|
|
1211
|
+
status.dirty();
|
|
1212
|
+
}
|
|
1103
1213
|
} else {
|
|
1104
1214
|
util.assertNever(check);
|
|
1105
1215
|
}
|
|
@@ -1146,9 +1256,21 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1146
1256
|
base64(message) {
|
|
1147
1257
|
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1148
1258
|
}
|
|
1259
|
+
base64url(message) {
|
|
1260
|
+
return this._addCheck({
|
|
1261
|
+
kind: "base64url",
|
|
1262
|
+
...errorUtil.errToObj(message)
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
jwt(options) {
|
|
1266
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1267
|
+
}
|
|
1149
1268
|
ip(options) {
|
|
1150
1269
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1151
1270
|
}
|
|
1271
|
+
cidr(options) {
|
|
1272
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1273
|
+
}
|
|
1152
1274
|
datetime(options) {
|
|
1153
1275
|
var _a, _b;
|
|
1154
1276
|
if (typeof options === "string") {
|
|
@@ -1239,8 +1361,7 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1239
1361
|
});
|
|
1240
1362
|
}
|
|
1241
1363
|
/**
|
|
1242
|
-
*
|
|
1243
|
-
* @see {@link ZodString.min}
|
|
1364
|
+
* Equivalent to `.min(1)`
|
|
1244
1365
|
*/
|
|
1245
1366
|
nonempty(message) {
|
|
1246
1367
|
return this.min(1, errorUtil.errToObj(message));
|
|
@@ -1302,9 +1423,15 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1302
1423
|
get isIP() {
|
|
1303
1424
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1304
1425
|
}
|
|
1426
|
+
get isCIDR() {
|
|
1427
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1428
|
+
}
|
|
1305
1429
|
get isBase64() {
|
|
1306
1430
|
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1307
1431
|
}
|
|
1432
|
+
get isBase64url() {
|
|
1433
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1434
|
+
}
|
|
1308
1435
|
get minLength() {
|
|
1309
1436
|
let min = null;
|
|
1310
1437
|
for (const ch of this._def.checks) {
|
|
@@ -1582,17 +1709,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
1582
1709
|
}
|
|
1583
1710
|
_parse(input) {
|
|
1584
1711
|
if (this._def.coerce) {
|
|
1585
|
-
|
|
1712
|
+
try {
|
|
1713
|
+
input.data = BigInt(input.data);
|
|
1714
|
+
} catch (_a) {
|
|
1715
|
+
return this._getInvalidInput(input);
|
|
1716
|
+
}
|
|
1586
1717
|
}
|
|
1587
1718
|
const parsedType = this._getType(input);
|
|
1588
1719
|
if (parsedType !== ZodParsedType.bigint) {
|
|
1589
|
-
|
|
1590
|
-
addIssueToContext(ctx2, {
|
|
1591
|
-
code: ZodIssueCode.invalid_type,
|
|
1592
|
-
expected: ZodParsedType.bigint,
|
|
1593
|
-
received: ctx2.parsedType
|
|
1594
|
-
});
|
|
1595
|
-
return INVALID;
|
|
1720
|
+
return this._getInvalidInput(input);
|
|
1596
1721
|
}
|
|
1597
1722
|
let ctx = void 0;
|
|
1598
1723
|
const status = new ParseStatus();
|
|
@@ -1639,6 +1764,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
1639
1764
|
}
|
|
1640
1765
|
return { status: status.value, value: input.data };
|
|
1641
1766
|
}
|
|
1767
|
+
_getInvalidInput(input) {
|
|
1768
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1769
|
+
addIssueToContext(ctx, {
|
|
1770
|
+
code: ZodIssueCode.invalid_type,
|
|
1771
|
+
expected: ZodParsedType.bigint,
|
|
1772
|
+
received: ctx.parsedType
|
|
1773
|
+
});
|
|
1774
|
+
return INVALID;
|
|
1775
|
+
}
|
|
1642
1776
|
gte(value, message) {
|
|
1643
1777
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1644
1778
|
}
|
|
@@ -4210,7 +4344,7 @@ function extractJSONSchema(schema, check, matches = []) {
|
|
|
4210
4344
|
}
|
|
4211
4345
|
|
|
4212
4346
|
// src/generator.ts
|
|
4213
|
-
function generateOpenAPI(opts, options) {
|
|
4347
|
+
async function generateOpenAPI(opts, options) {
|
|
4214
4348
|
const throwOnMissingTagDefinition = options?.throwOnMissingTagDefinition ?? false;
|
|
4215
4349
|
const ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
|
|
4216
4350
|
const builder = new OpenApiBuilder({
|
|
@@ -4218,197 +4352,212 @@ function generateOpenAPI(opts, options) {
|
|
|
4218
4352
|
openapi: "3.1.0"
|
|
4219
4353
|
});
|
|
4220
4354
|
const rootTags = opts.tags?.map((tag) => tag.name) ?? [];
|
|
4221
|
-
const
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
}
|
|
4227
|
-
|
|
4228
|
-
|
|
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;
|
|
4355
|
+
const pending = [{
|
|
4356
|
+
path: [],
|
|
4357
|
+
router: opts.router
|
|
4358
|
+
}];
|
|
4359
|
+
for (const item of pending) {
|
|
4360
|
+
const lazies = eachContractProcedureLeaf(item, ({ contract, path }) => {
|
|
4361
|
+
if (!isContractProcedure(contract)) {
|
|
4362
|
+
return;
|
|
4235
4363
|
}
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
);
|
|
4364
|
+
const internal = contract.zz$cp;
|
|
4365
|
+
if (ignoreUndefinedPathProcedures && internal.path === void 0) {
|
|
4366
|
+
return;
|
|
4240
4367
|
}
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4368
|
+
const httpPath = internal.path ?? `/${path.map(encodeURIComponent).join("/")}`;
|
|
4369
|
+
const method = internal.method ?? "POST";
|
|
4370
|
+
let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
|
|
4371
|
+
const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
|
|
4372
|
+
const params = (() => {
|
|
4373
|
+
const names = httpPath.match(/\{([^}]+)\}/g);
|
|
4374
|
+
if (!names || !names.length) {
|
|
4375
|
+
return void 0;
|
|
4248
4376
|
}
|
|
4249
|
-
if (
|
|
4377
|
+
if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
|
|
4250
4378
|
throw new Error(
|
|
4251
|
-
`
|
|
4379
|
+
`When path has parameters, input schema must be an object [${path.join(".")}]`
|
|
4252
4380
|
);
|
|
4253
4381
|
}
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
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
|
-
{}
|
|
4382
|
+
return names.map((raw) => raw.slice(1, -1)).map((name) => {
|
|
4383
|
+
let schema = inputSchema.properties?.[name];
|
|
4384
|
+
const required = inputSchema.required?.includes(name);
|
|
4385
|
+
if (schema === void 0) {
|
|
4386
|
+
throw new Error(
|
|
4387
|
+
`Parameter ${name} is missing in input schema [${path.join(".")}]`
|
|
4286
4388
|
);
|
|
4287
|
-
}
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
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]) => {
|
|
4389
|
+
}
|
|
4390
|
+
if (!required) {
|
|
4391
|
+
throw new Error(
|
|
4392
|
+
`Parameter ${name} must be required in input schema [${path.join(".")}]`
|
|
4393
|
+
);
|
|
4394
|
+
}
|
|
4309
4395
|
const examples = inputSchema.examples?.filter((example) => {
|
|
4310
4396
|
return isPlainObject(example) && name in example;
|
|
4311
4397
|
}).map((example) => {
|
|
4312
4398
|
return example[name];
|
|
4313
4399
|
});
|
|
4314
|
-
|
|
4400
|
+
schema = {
|
|
4315
4401
|
examples: examples?.length ? examples : void 0,
|
|
4316
4402
|
...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
|
|
4317
4403
|
};
|
|
4404
|
+
inputSchema = {
|
|
4405
|
+
...inputSchema,
|
|
4406
|
+
properties: inputSchema.properties ? Object.entries(inputSchema.properties).reduce(
|
|
4407
|
+
(acc, [key, value]) => {
|
|
4408
|
+
if (key !== name) {
|
|
4409
|
+
acc[key] = value;
|
|
4410
|
+
}
|
|
4411
|
+
return acc;
|
|
4412
|
+
},
|
|
4413
|
+
{}
|
|
4414
|
+
) : void 0,
|
|
4415
|
+
required: inputSchema.required?.filter((v) => v !== name),
|
|
4416
|
+
examples: inputSchema.examples?.map((example) => {
|
|
4417
|
+
if (!isPlainObject(example))
|
|
4418
|
+
return example;
|
|
4419
|
+
return Object.entries(example).reduce(
|
|
4420
|
+
(acc, [key, value]) => {
|
|
4421
|
+
if (key !== name) {
|
|
4422
|
+
acc[key] = value;
|
|
4423
|
+
}
|
|
4424
|
+
return acc;
|
|
4425
|
+
},
|
|
4426
|
+
{}
|
|
4427
|
+
);
|
|
4428
|
+
})
|
|
4429
|
+
};
|
|
4318
4430
|
return {
|
|
4319
4431
|
name,
|
|
4320
|
-
in: "
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
schema: schema_,
|
|
4432
|
+
in: "path",
|
|
4433
|
+
required: true,
|
|
4434
|
+
schema,
|
|
4324
4435
|
example: internal.inputExample?.[name]
|
|
4325
4436
|
};
|
|
4437
|
+
});
|
|
4438
|
+
})();
|
|
4439
|
+
const query = (() => {
|
|
4440
|
+
if (method !== "GET" || Object.keys(inputSchema).length === 0) {
|
|
4441
|
+
return void 0;
|
|
4326
4442
|
}
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
return
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4443
|
+
if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
|
|
4444
|
+
throw new Error(
|
|
4445
|
+
`When method is GET, input schema must be an object [${path.join(".")}]`
|
|
4446
|
+
);
|
|
4447
|
+
}
|
|
4448
|
+
return Object.entries(inputSchema.properties ?? {}).map(
|
|
4449
|
+
([name, schema]) => {
|
|
4450
|
+
const examples = inputSchema.examples?.filter((example) => {
|
|
4451
|
+
return isPlainObject(example) && name in example;
|
|
4452
|
+
}).map((example) => {
|
|
4453
|
+
return example[name];
|
|
4454
|
+
});
|
|
4455
|
+
const schema_ = {
|
|
4456
|
+
examples: examples?.length ? examples : void 0,
|
|
4457
|
+
...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
|
|
4458
|
+
};
|
|
4459
|
+
return {
|
|
4460
|
+
name,
|
|
4461
|
+
in: "query",
|
|
4462
|
+
style: "deepObject",
|
|
4463
|
+
required: inputSchema?.required?.includes(name) ?? false,
|
|
4464
|
+
schema: schema_,
|
|
4465
|
+
example: internal.inputExample?.[name]
|
|
4466
|
+
};
|
|
4347
4467
|
}
|
|
4348
|
-
|
|
4349
|
-
}
|
|
4350
|
-
const
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
}
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4468
|
+
);
|
|
4469
|
+
})();
|
|
4470
|
+
const parameters = [...params ?? [], ...query ?? []];
|
|
4471
|
+
const requestBody = (() => {
|
|
4472
|
+
if (method === "GET") {
|
|
4473
|
+
return void 0;
|
|
4474
|
+
}
|
|
4475
|
+
const { schema, matches } = extractJSONSchema(inputSchema, isFileSchema);
|
|
4476
|
+
const files = matches;
|
|
4477
|
+
const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
|
|
4478
|
+
if (files.length) {
|
|
4479
|
+
parameters.push({
|
|
4480
|
+
name: "content-disposition",
|
|
4481
|
+
in: "header",
|
|
4482
|
+
required: schema === void 0,
|
|
4483
|
+
schema: {
|
|
4484
|
+
type: "string",
|
|
4485
|
+
pattern: "filename",
|
|
4486
|
+
example: 'filename="file.png"',
|
|
4487
|
+
description: "To define the file name. Required when the request body is a file."
|
|
4488
|
+
}
|
|
4489
|
+
});
|
|
4490
|
+
}
|
|
4491
|
+
const content = {};
|
|
4492
|
+
for (const file of files) {
|
|
4493
|
+
content[file.contentMediaType] = {
|
|
4494
|
+
schema: file
|
|
4495
|
+
};
|
|
4496
|
+
}
|
|
4497
|
+
if (schema !== void 0) {
|
|
4498
|
+
content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
|
|
4499
|
+
schema,
|
|
4500
|
+
example: internal.inputExample
|
|
4501
|
+
};
|
|
4502
|
+
}
|
|
4503
|
+
return {
|
|
4504
|
+
required: Boolean(internal.InputSchema?.isOptional()),
|
|
4505
|
+
content
|
|
4375
4506
|
};
|
|
4376
|
-
}
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4507
|
+
})();
|
|
4508
|
+
const successResponse = (() => {
|
|
4509
|
+
const { schema, matches } = extractJSONSchema(outputSchema, isFileSchema);
|
|
4510
|
+
const files = matches;
|
|
4511
|
+
const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
|
|
4512
|
+
const content = {};
|
|
4513
|
+
for (const file of files) {
|
|
4514
|
+
content[file.contentMediaType] = {
|
|
4515
|
+
schema: file
|
|
4516
|
+
};
|
|
4517
|
+
}
|
|
4518
|
+
if (schema !== void 0) {
|
|
4519
|
+
content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
|
|
4520
|
+
schema,
|
|
4521
|
+
example: internal.outputExample
|
|
4522
|
+
};
|
|
4523
|
+
}
|
|
4524
|
+
return {
|
|
4525
|
+
description: "OK",
|
|
4526
|
+
content
|
|
4381
4527
|
};
|
|
4528
|
+
})();
|
|
4529
|
+
if (throwOnMissingTagDefinition && internal.tags) {
|
|
4530
|
+
const missingTag = internal.tags.find((tag) => !rootTags.includes(tag));
|
|
4531
|
+
if (missingTag !== void 0) {
|
|
4532
|
+
throw new Error(
|
|
4533
|
+
`Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path.join(".")}]`
|
|
4534
|
+
);
|
|
4535
|
+
}
|
|
4382
4536
|
}
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4537
|
+
const operation = {
|
|
4538
|
+
summary: internal.summary,
|
|
4539
|
+
description: internal.description,
|
|
4540
|
+
deprecated: internal.deprecated,
|
|
4541
|
+
tags: internal.tags,
|
|
4542
|
+
operationId: path.join("."),
|
|
4543
|
+
parameters: parameters.length ? parameters : void 0,
|
|
4544
|
+
requestBody,
|
|
4545
|
+
responses: {
|
|
4546
|
+
200: successResponse
|
|
4547
|
+
}
|
|
4386
4548
|
};
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
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
|
|
4549
|
+
builder.addPath(httpPath, {
|
|
4550
|
+
[method.toLocaleLowerCase()]: operation
|
|
4551
|
+
});
|
|
4410
4552
|
});
|
|
4411
|
-
|
|
4553
|
+
for (const lazy of lazies) {
|
|
4554
|
+
const router = (await lazy.lazy[LAZY_LOADER_SYMBOL]()).default;
|
|
4555
|
+
pending.push({
|
|
4556
|
+
path: lazy.path,
|
|
4557
|
+
router
|
|
4558
|
+
});
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4412
4561
|
return preSerialize(builder.getSpec());
|
|
4413
4562
|
}
|
|
4414
4563
|
function isFileSchema(schema) {
|
|
@@ -4419,3 +4568,4 @@ function isFileSchema(schema) {
|
|
|
4419
4568
|
export {
|
|
4420
4569
|
generateOpenAPI
|
|
4421
4570
|
};
|
|
4571
|
+
//# sourceMappingURL=index.js.map
|