@orpc/openapi 0.0.0-next.db1f26d → 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.
|
@@ -42,8 +42,12 @@ function eachContractProcedureLeaf(options, callback, result = [], isCurrentRout
|
|
|
42
42
|
}
|
|
43
43
|
return result;
|
|
44
44
|
}
|
|
45
|
+
function standardizeHTTPPath(path) {
|
|
46
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
47
|
+
}
|
|
45
48
|
|
|
46
49
|
export {
|
|
47
|
-
eachContractProcedureLeaf
|
|
50
|
+
eachContractProcedureLeaf,
|
|
51
|
+
standardizeHTTPPath
|
|
48
52
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
53
|
+
//# sourceMappingURL=chunk-7HD5IZWG.js.map
|
package/dist/fetch.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
eachContractProcedureLeaf
|
|
3
|
-
|
|
2
|
+
eachContractProcedureLeaf,
|
|
3
|
+
standardizeHTTPPath
|
|
4
|
+
} from "./chunk-7HD5IZWG.js";
|
|
4
5
|
|
|
5
6
|
// src/fetch/base-handler.ts
|
|
6
|
-
import { ORPC_HEADER, standardizeHTTPPath } from "@orpc/contract";
|
|
7
7
|
import { createProcedureCaller, isLazy, isProcedure, LAZY_LOADER_SYMBOL, LAZY_ROUTER_PREFIX_SYMBOL, ORPCError } from "@orpc/server";
|
|
8
|
-
import { isPlainObject, mapValues, trim, value } from "@orpc/shared";
|
|
8
|
+
import { executeWithHooks, isPlainObject, mapValues, ORPC_PROTOCOL_HEADER, ORPC_PROTOCOL_VALUE, trim, value } from "@orpc/shared";
|
|
9
9
|
import { OpenAPIDeserializer, OpenAPISerializer, zodCoerce } from "@orpc/transformer";
|
|
10
10
|
function createOpenAPIHandler(createHonoRouter) {
|
|
11
11
|
const resolveRouter = createResolveRouter(createHonoRouter);
|
|
12
12
|
return async (options) => {
|
|
13
|
-
if (options.request.headers.get(
|
|
13
|
+
if (options.request.headers.get(ORPC_PROTOCOL_HEADER)?.includes(ORPC_PROTOCOL_VALUE)) {
|
|
14
14
|
return void 0;
|
|
15
15
|
}
|
|
16
16
|
const context = await value(options.context);
|
|
@@ -33,8 +33,8 @@ function createOpenAPIHandler(createHonoRouter) {
|
|
|
33
33
|
message: "Not found"
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
const params = procedure.zz$p.contract.
|
|
37
|
-
procedure.zz$p.contract.
|
|
36
|
+
const params = procedure.zz$p.contract["~orpc"].InputSchema ? zodCoerce(
|
|
37
|
+
procedure.zz$p.contract["~orpc"].InputSchema,
|
|
38
38
|
match.params,
|
|
39
39
|
{ bracketNotation: true }
|
|
40
40
|
) : match.params;
|
|
@@ -45,7 +45,7 @@ function createOpenAPIHandler(createHonoRouter) {
|
|
|
45
45
|
procedure,
|
|
46
46
|
path
|
|
47
47
|
});
|
|
48
|
-
const output = await caller(mergedInput);
|
|
48
|
+
const output = await caller(mergedInput, { signal: options.signal });
|
|
49
49
|
const { body, headers } = serializer.serialize(output);
|
|
50
50
|
return new Response(body, {
|
|
51
51
|
status: 200,
|
|
@@ -53,10 +53,15 @@ function createOpenAPIHandler(createHonoRouter) {
|
|
|
53
53
|
});
|
|
54
54
|
};
|
|
55
55
|
try {
|
|
56
|
-
return await
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
return await executeWithHooks({
|
|
57
|
+
context,
|
|
58
|
+
hooks: options,
|
|
59
|
+
execute: handler,
|
|
60
|
+
input: options.request,
|
|
61
|
+
meta: {
|
|
62
|
+
signal: options.signal
|
|
63
|
+
}
|
|
64
|
+
});
|
|
60
65
|
} catch (e) {
|
|
61
66
|
const error = toORPCError(e);
|
|
62
67
|
try {
|
|
@@ -83,8 +88,8 @@ var pendingCache = /* @__PURE__ */ new Map();
|
|
|
83
88
|
function createResolveRouter(createHonoRouter) {
|
|
84
89
|
const addRoutes = (routing, pending, options) => {
|
|
85
90
|
const lazies = eachContractProcedureLeaf(options, ({ path, contract }) => {
|
|
86
|
-
const method = contract.
|
|
87
|
-
const httpPath = contract.
|
|
91
|
+
const method = contract["~orpc"].route?.method ?? "POST";
|
|
92
|
+
const httpPath = contract["~orpc"].route?.path ? openAPIPathToRouterPath(contract["~orpc"].route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
88
93
|
routing.add(method, httpPath, path);
|
|
89
94
|
});
|
|
90
95
|
pending.ref.push(...lazies);
|
|
@@ -159,7 +164,7 @@ function mergeParamsAndInput(coercedParams, input) {
|
|
|
159
164
|
}
|
|
160
165
|
async function deserializeInput(request, procedure) {
|
|
161
166
|
const deserializer = new OpenAPIDeserializer({
|
|
162
|
-
schema: procedure.zz$p.contract.
|
|
167
|
+
schema: procedure.zz$p.contract["~orpc"].InputSchema
|
|
163
168
|
});
|
|
164
169
|
try {
|
|
165
170
|
return await deserializer.deserialize(request);
|
|
@@ -182,13 +187,13 @@ function openAPIPathToRouterPath(path) {
|
|
|
182
187
|
return standardizeHTTPPath(path).replace(/\{([^}]+)\}/g, ":$1");
|
|
183
188
|
}
|
|
184
189
|
|
|
185
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
190
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router.js
|
|
186
191
|
var METHOD_NAME_ALL = "ALL";
|
|
187
192
|
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
188
193
|
var UnsupportedPathError = class extends Error {
|
|
189
194
|
};
|
|
190
195
|
|
|
191
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
196
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/utils/url.js
|
|
192
197
|
var checkOptionalParameter = (path) => {
|
|
193
198
|
if (!path.match(/\:.+\?$/)) {
|
|
194
199
|
return null;
|
|
@@ -217,7 +222,7 @@ var checkOptionalParameter = (path) => {
|
|
|
217
222
|
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
218
223
|
};
|
|
219
224
|
|
|
220
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
225
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
221
226
|
var LABEL_REG_EXP_STR = "[^/]+";
|
|
222
227
|
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
223
228
|
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
@@ -322,7 +327,7 @@ var Node = class {
|
|
|
322
327
|
}
|
|
323
328
|
};
|
|
324
329
|
|
|
325
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
330
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
326
331
|
var Trie = class {
|
|
327
332
|
#context = { varIndex: 0 };
|
|
328
333
|
#root = new Node();
|
|
@@ -378,7 +383,7 @@ var Trie = class {
|
|
|
378
383
|
}
|
|
379
384
|
};
|
|
380
385
|
|
|
381
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
386
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
382
387
|
var emptyParam = [];
|
|
383
388
|
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
384
389
|
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
@@ -579,7 +584,7 @@ function createOpenAPIServerHandler() {
|
|
|
579
584
|
return createOpenAPIHandler(() => new RegExpRouter());
|
|
580
585
|
}
|
|
581
586
|
|
|
582
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
587
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/linear-router/router.js
|
|
583
588
|
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
584
589
|
var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
585
590
|
var splitByStarRe = /\*/;
|
|
@@ -697,7 +702,6 @@ export {
|
|
|
697
702
|
createOpenAPIHandler,
|
|
698
703
|
createOpenAPIServerHandler,
|
|
699
704
|
createOpenAPIServerlessHandler,
|
|
700
|
-
createResolveRouter
|
|
701
|
-
openAPIPathToRouterPath
|
|
705
|
+
createResolveRouter
|
|
702
706
|
};
|
|
703
707
|
//# sourceMappingURL=fetch.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
eachContractProcedureLeaf
|
|
3
|
-
|
|
2
|
+
eachContractProcedureLeaf,
|
|
3
|
+
standardizeHTTPPath
|
|
4
|
+
} from "./chunk-7HD5IZWG.js";
|
|
4
5
|
|
|
5
6
|
// src/generator.ts
|
|
6
7
|
import { isContractProcedure } from "@orpc/contract";
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
Format
|
|
23
24
|
} from "json-schema-typed/draft-2020-12";
|
|
24
25
|
|
|
25
|
-
// ../../node_modules/.pnpm/zod@3.
|
|
26
|
+
// ../../node_modules/.pnpm/zod@3.24.1/node_modules/zod/lib/index.mjs
|
|
26
27
|
var util;
|
|
27
28
|
(function(util2) {
|
|
28
29
|
util2.assertEqual = (val) => val;
|
|
@@ -173,6 +174,9 @@ var ZodIssueCode = util.arrayToEnum([
|
|
|
173
174
|
"not_finite"
|
|
174
175
|
]);
|
|
175
176
|
var ZodError = class _ZodError extends Error {
|
|
177
|
+
get errors() {
|
|
178
|
+
return this.issues;
|
|
179
|
+
}
|
|
176
180
|
constructor(issues) {
|
|
177
181
|
super();
|
|
178
182
|
this.issues = [];
|
|
@@ -191,9 +195,6 @@ var ZodError = class _ZodError extends Error {
|
|
|
191
195
|
this.name = "ZodError";
|
|
192
196
|
this.issues = issues;
|
|
193
197
|
}
|
|
194
|
-
get errors() {
|
|
195
|
-
return this.issues;
|
|
196
|
-
}
|
|
197
198
|
format(_mapper) {
|
|
198
199
|
const mapper = _mapper || function(issue) {
|
|
199
200
|
return issue.message;
|
|
@@ -400,8 +401,11 @@ function addIssueToContext(ctx, issueData) {
|
|
|
400
401
|
path: ctx.path,
|
|
401
402
|
errorMaps: [
|
|
402
403
|
ctx.common.contextualErrorMap,
|
|
404
|
+
// contextual error map is first priority
|
|
403
405
|
ctx.schemaErrorMap,
|
|
406
|
+
// then schema-bound map if available
|
|
404
407
|
overrideMap,
|
|
408
|
+
// then global override map
|
|
405
409
|
overrideMap === errorMap ? void 0 : errorMap
|
|
406
410
|
// then global default map
|
|
407
411
|
].filter((x) => !!x)
|
|
@@ -552,34 +556,6 @@ function processCreateParams(params) {
|
|
|
552
556
|
return { errorMap: customMap, description };
|
|
553
557
|
}
|
|
554
558
|
var ZodType = class {
|
|
555
|
-
constructor(def) {
|
|
556
|
-
this.spa = this.safeParseAsync;
|
|
557
|
-
this._def = def;
|
|
558
|
-
this.parse = this.parse.bind(this);
|
|
559
|
-
this.safeParse = this.safeParse.bind(this);
|
|
560
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
561
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
562
|
-
this.spa = this.spa.bind(this);
|
|
563
|
-
this.refine = this.refine.bind(this);
|
|
564
|
-
this.refinement = this.refinement.bind(this);
|
|
565
|
-
this.superRefine = this.superRefine.bind(this);
|
|
566
|
-
this.optional = this.optional.bind(this);
|
|
567
|
-
this.nullable = this.nullable.bind(this);
|
|
568
|
-
this.nullish = this.nullish.bind(this);
|
|
569
|
-
this.array = this.array.bind(this);
|
|
570
|
-
this.promise = this.promise.bind(this);
|
|
571
|
-
this.or = this.or.bind(this);
|
|
572
|
-
this.and = this.and.bind(this);
|
|
573
|
-
this.transform = this.transform.bind(this);
|
|
574
|
-
this.brand = this.brand.bind(this);
|
|
575
|
-
this.default = this.default.bind(this);
|
|
576
|
-
this.catch = this.catch.bind(this);
|
|
577
|
-
this.describe = this.describe.bind(this);
|
|
578
|
-
this.pipe = this.pipe.bind(this);
|
|
579
|
-
this.readonly = this.readonly.bind(this);
|
|
580
|
-
this.isNullable = this.isNullable.bind(this);
|
|
581
|
-
this.isOptional = this.isOptional.bind(this);
|
|
582
|
-
}
|
|
583
559
|
get description() {
|
|
584
560
|
return this._def.description;
|
|
585
561
|
}
|
|
@@ -643,6 +619,43 @@ var ZodType = class {
|
|
|
643
619
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
644
620
|
return handleResult(ctx, result);
|
|
645
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
|
+
}
|
|
646
659
|
async parseAsync(data, params) {
|
|
647
660
|
const result = await this.safeParseAsync(data, params);
|
|
648
661
|
if (result.success)
|
|
@@ -720,6 +733,39 @@ var ZodType = class {
|
|
|
720
733
|
superRefine(refinement) {
|
|
721
734
|
return this._refinement(refinement);
|
|
722
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
|
+
}
|
|
723
769
|
optional() {
|
|
724
770
|
return ZodOptional.create(this, this._def);
|
|
725
771
|
}
|
|
@@ -730,7 +776,7 @@ var ZodType = class {
|
|
|
730
776
|
return this.nullable().optional();
|
|
731
777
|
}
|
|
732
778
|
array() {
|
|
733
|
-
return ZodArray.create(this
|
|
779
|
+
return ZodArray.create(this);
|
|
734
780
|
}
|
|
735
781
|
promise() {
|
|
736
782
|
return ZodPromise.create(this, this._def);
|
|
@@ -796,16 +842,20 @@ var ZodType = class {
|
|
|
796
842
|
};
|
|
797
843
|
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
798
844
|
var cuid2Regex = /^[0-9a-z]+$/;
|
|
799
|
-
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}
|
|
845
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
800
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;
|
|
801
847
|
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
848
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
802
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)?)??$/;
|
|
803
850
|
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
804
851
|
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
805
852
|
var emojiRegex;
|
|
806
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])$/;
|
|
807
|
-
var
|
|
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])$/;
|
|
808
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}(=)?))?$/;
|
|
809
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])))`;
|
|
810
860
|
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
811
861
|
function timeRegexSource(args) {
|
|
@@ -838,6 +888,33 @@ function isValidIP(ip, version) {
|
|
|
838
888
|
}
|
|
839
889
|
return false;
|
|
840
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
|
+
}
|
|
841
918
|
var ZodString = class _ZodString extends ZodType {
|
|
842
919
|
_parse(input) {
|
|
843
920
|
if (this._def.coerce) {
|
|
@@ -1094,6 +1171,26 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1094
1171
|
});
|
|
1095
1172
|
status.dirty();
|
|
1096
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
|
+
}
|
|
1097
1194
|
} else if (check.kind === "base64") {
|
|
1098
1195
|
if (!base64Regex.test(input.data)) {
|
|
1099
1196
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1104,6 +1201,16 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1104
1201
|
});
|
|
1105
1202
|
status.dirty();
|
|
1106
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
|
+
}
|
|
1107
1214
|
} else {
|
|
1108
1215
|
util.assertNever(check);
|
|
1109
1216
|
}
|
|
@@ -1150,9 +1257,21 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1150
1257
|
base64(message) {
|
|
1151
1258
|
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1152
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
|
+
}
|
|
1153
1269
|
ip(options) {
|
|
1154
1270
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1155
1271
|
}
|
|
1272
|
+
cidr(options) {
|
|
1273
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1274
|
+
}
|
|
1156
1275
|
datetime(options) {
|
|
1157
1276
|
var _a, _b;
|
|
1158
1277
|
if (typeof options === "string") {
|
|
@@ -1243,8 +1362,7 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1243
1362
|
});
|
|
1244
1363
|
}
|
|
1245
1364
|
/**
|
|
1246
|
-
*
|
|
1247
|
-
* @see {@link ZodString.min}
|
|
1365
|
+
* Equivalent to `.min(1)`
|
|
1248
1366
|
*/
|
|
1249
1367
|
nonempty(message) {
|
|
1250
1368
|
return this.min(1, errorUtil.errToObj(message));
|
|
@@ -1306,9 +1424,15 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1306
1424
|
get isIP() {
|
|
1307
1425
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1308
1426
|
}
|
|
1427
|
+
get isCIDR() {
|
|
1428
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1429
|
+
}
|
|
1309
1430
|
get isBase64() {
|
|
1310
1431
|
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1311
1432
|
}
|
|
1433
|
+
get isBase64url() {
|
|
1434
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1435
|
+
}
|
|
1312
1436
|
get minLength() {
|
|
1313
1437
|
let min = null;
|
|
1314
1438
|
for (const ch of this._def.checks) {
|
|
@@ -1586,17 +1710,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
1586
1710
|
}
|
|
1587
1711
|
_parse(input) {
|
|
1588
1712
|
if (this._def.coerce) {
|
|
1589
|
-
|
|
1713
|
+
try {
|
|
1714
|
+
input.data = BigInt(input.data);
|
|
1715
|
+
} catch (_a) {
|
|
1716
|
+
return this._getInvalidInput(input);
|
|
1717
|
+
}
|
|
1590
1718
|
}
|
|
1591
1719
|
const parsedType = this._getType(input);
|
|
1592
1720
|
if (parsedType !== ZodParsedType.bigint) {
|
|
1593
|
-
|
|
1594
|
-
addIssueToContext(ctx2, {
|
|
1595
|
-
code: ZodIssueCode.invalid_type,
|
|
1596
|
-
expected: ZodParsedType.bigint,
|
|
1597
|
-
received: ctx2.parsedType
|
|
1598
|
-
});
|
|
1599
|
-
return INVALID;
|
|
1721
|
+
return this._getInvalidInput(input);
|
|
1600
1722
|
}
|
|
1601
1723
|
let ctx = void 0;
|
|
1602
1724
|
const status = new ParseStatus();
|
|
@@ -1643,6 +1765,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
1643
1765
|
}
|
|
1644
1766
|
return { status: status.value, value: input.data };
|
|
1645
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
|
+
}
|
|
1646
1777
|
gte(value, message) {
|
|
1647
1778
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1648
1779
|
}
|
|
@@ -3813,10 +3944,15 @@ var NON_LOGIC_KEYWORDS = [
|
|
|
3813
3944
|
var UNSUPPORTED_JSON_SCHEMA = { not: {} };
|
|
3814
3945
|
var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
|
|
3815
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;
|
|
3816
3952
|
if (!options?.isHandledCustomJSONSchema) {
|
|
3817
|
-
const customJSONSchema = getCustomJSONSchema(
|
|
3953
|
+
const customJSONSchema = getCustomJSONSchema(schema__._def, options);
|
|
3818
3954
|
if (customJSONSchema) {
|
|
3819
|
-
const json = zodToJsonSchema(
|
|
3955
|
+
const json = zodToJsonSchema(schema__, {
|
|
3820
3956
|
...options,
|
|
3821
3957
|
isHandledCustomJSONSchema: true
|
|
3822
3958
|
});
|
|
@@ -3827,13 +3963,13 @@ function zodToJsonSchema(schema, options) {
|
|
|
3827
3963
|
}
|
|
3828
3964
|
}
|
|
3829
3965
|
const childOptions = { ...options, isHandledCustomJSONSchema: false };
|
|
3830
|
-
const customType = getCustomZodType(
|
|
3966
|
+
const customType = getCustomZodType(schema__._def);
|
|
3831
3967
|
switch (customType) {
|
|
3832
3968
|
case "Blob": {
|
|
3833
3969
|
return { type: "string", contentMediaType: "*/*" };
|
|
3834
3970
|
}
|
|
3835
3971
|
case "File": {
|
|
3836
|
-
const mimeType = getCustomZodFileMimeType(
|
|
3972
|
+
const mimeType = getCustomZodFileMimeType(schema__._def) ?? "*/*";
|
|
3837
3973
|
return { type: "string", contentMediaType: mimeType };
|
|
3838
3974
|
}
|
|
3839
3975
|
case "Invalid Date": {
|
|
@@ -3850,10 +3986,10 @@ function zodToJsonSchema(schema, options) {
|
|
|
3850
3986
|
}
|
|
3851
3987
|
}
|
|
3852
3988
|
const _expectedCustomType = customType;
|
|
3853
|
-
const typeName =
|
|
3989
|
+
const typeName = schema__._def.typeName;
|
|
3854
3990
|
switch (typeName) {
|
|
3855
3991
|
case ZodFirstPartyTypeKind.ZodString: {
|
|
3856
|
-
const schema_ =
|
|
3992
|
+
const schema_ = schema__;
|
|
3857
3993
|
const json = { type: "string" };
|
|
3858
3994
|
for (const check of schema_._def.checks) {
|
|
3859
3995
|
switch (check.kind) {
|
|
@@ -3921,6 +4057,12 @@ function zodToJsonSchema(schema, options) {
|
|
|
3921
4057
|
case "ip":
|
|
3922
4058
|
json.format = Format.IPv4;
|
|
3923
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;
|
|
3924
4066
|
default: {
|
|
3925
4067
|
const _expect = check.kind;
|
|
3926
4068
|
}
|
|
@@ -3929,7 +4071,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
3929
4071
|
return json;
|
|
3930
4072
|
}
|
|
3931
4073
|
case ZodFirstPartyTypeKind.ZodNumber: {
|
|
3932
|
-
const schema_ =
|
|
4074
|
+
const schema_ = schema__;
|
|
3933
4075
|
const json = { type: "number" };
|
|
3934
4076
|
for (const check of schema_._def.checks) {
|
|
3935
4077
|
switch (check.kind) {
|
|
@@ -3974,23 +4116,23 @@ function zodToJsonSchema(schema, options) {
|
|
|
3974
4116
|
return UNDEFINED_JSON_SCHEMA;
|
|
3975
4117
|
}
|
|
3976
4118
|
case ZodFirstPartyTypeKind.ZodLiteral: {
|
|
3977
|
-
const schema_ =
|
|
4119
|
+
const schema_ = schema__;
|
|
3978
4120
|
return { const: schema_._def.value };
|
|
3979
4121
|
}
|
|
3980
4122
|
case ZodFirstPartyTypeKind.ZodEnum: {
|
|
3981
|
-
const schema_ =
|
|
4123
|
+
const schema_ = schema__;
|
|
3982
4124
|
return {
|
|
3983
4125
|
enum: schema_._def.values
|
|
3984
4126
|
};
|
|
3985
4127
|
}
|
|
3986
4128
|
case ZodFirstPartyTypeKind.ZodNativeEnum: {
|
|
3987
|
-
const schema_ =
|
|
4129
|
+
const schema_ = schema__;
|
|
3988
4130
|
return {
|
|
3989
4131
|
enum: Object.values(schema_._def.values)
|
|
3990
4132
|
};
|
|
3991
4133
|
}
|
|
3992
4134
|
case ZodFirstPartyTypeKind.ZodArray: {
|
|
3993
|
-
const schema_ =
|
|
4135
|
+
const schema_ = schema__;
|
|
3994
4136
|
const def = schema_._def;
|
|
3995
4137
|
const json = { type: "array" };
|
|
3996
4138
|
if (def.exactLength) {
|
|
@@ -4006,7 +4148,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4006
4148
|
return json;
|
|
4007
4149
|
}
|
|
4008
4150
|
case ZodFirstPartyTypeKind.ZodTuple: {
|
|
4009
|
-
const schema_ =
|
|
4151
|
+
const schema_ = schema__;
|
|
4010
4152
|
const prefixItems = [];
|
|
4011
4153
|
const json = { type: "array" };
|
|
4012
4154
|
for (const item of schema_._def.items) {
|
|
@@ -4024,7 +4166,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4024
4166
|
return json;
|
|
4025
4167
|
}
|
|
4026
4168
|
case ZodFirstPartyTypeKind.ZodObject: {
|
|
4027
|
-
const schema_ =
|
|
4169
|
+
const schema_ = schema__;
|
|
4028
4170
|
const json = { type: "object" };
|
|
4029
4171
|
const properties = {};
|
|
4030
4172
|
const required = [];
|
|
@@ -4060,7 +4202,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4060
4202
|
return json;
|
|
4061
4203
|
}
|
|
4062
4204
|
case ZodFirstPartyTypeKind.ZodRecord: {
|
|
4063
|
-
const schema_ =
|
|
4205
|
+
const schema_ = schema__;
|
|
4064
4206
|
const json = { type: "object" };
|
|
4065
4207
|
json.additionalProperties = zodToJsonSchema(
|
|
4066
4208
|
schema_._def.valueType,
|
|
@@ -4069,14 +4211,14 @@ function zodToJsonSchema(schema, options) {
|
|
|
4069
4211
|
return json;
|
|
4070
4212
|
}
|
|
4071
4213
|
case ZodFirstPartyTypeKind.ZodSet: {
|
|
4072
|
-
const schema_ =
|
|
4214
|
+
const schema_ = schema__;
|
|
4073
4215
|
return {
|
|
4074
4216
|
type: "array",
|
|
4075
4217
|
items: zodToJsonSchema(schema_._def.valueType, childOptions)
|
|
4076
4218
|
};
|
|
4077
4219
|
}
|
|
4078
4220
|
case ZodFirstPartyTypeKind.ZodMap: {
|
|
4079
|
-
const schema_ =
|
|
4221
|
+
const schema_ = schema__;
|
|
4080
4222
|
return {
|
|
4081
4223
|
type: "array",
|
|
4082
4224
|
items: {
|
|
@@ -4092,7 +4234,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4092
4234
|
}
|
|
4093
4235
|
case ZodFirstPartyTypeKind.ZodUnion:
|
|
4094
4236
|
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
|
|
4095
|
-
const schema_ =
|
|
4237
|
+
const schema_ = schema__;
|
|
4096
4238
|
const anyOf = [];
|
|
4097
4239
|
for (const s of schema_._def.options) {
|
|
4098
4240
|
anyOf.push(zodToJsonSchema(s, childOptions));
|
|
@@ -4100,7 +4242,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4100
4242
|
return { anyOf };
|
|
4101
4243
|
}
|
|
4102
4244
|
case ZodFirstPartyTypeKind.ZodIntersection: {
|
|
4103
|
-
const schema_ =
|
|
4245
|
+
const schema_ = schema__;
|
|
4104
4246
|
const allOf = [];
|
|
4105
4247
|
for (const s of [schema_._def.left, schema_._def.right]) {
|
|
4106
4248
|
allOf.push(zodToJsonSchema(s, childOptions));
|
|
@@ -4108,7 +4250,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4108
4250
|
return { allOf };
|
|
4109
4251
|
}
|
|
4110
4252
|
case ZodFirstPartyTypeKind.ZodLazy: {
|
|
4111
|
-
const schema_ =
|
|
4253
|
+
const schema_ = schema__;
|
|
4112
4254
|
const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
|
|
4113
4255
|
const lazyDepth = childOptions?.lazyDepth ?? 0;
|
|
4114
4256
|
if (lazyDepth > maxLazyDepth) {
|
|
@@ -4125,44 +4267,44 @@ function zodToJsonSchema(schema, options) {
|
|
|
4125
4267
|
return {};
|
|
4126
4268
|
}
|
|
4127
4269
|
case ZodFirstPartyTypeKind.ZodOptional: {
|
|
4128
|
-
const schema_ =
|
|
4270
|
+
const schema_ = schema__;
|
|
4129
4271
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4130
4272
|
return {
|
|
4131
4273
|
anyOf: [UNDEFINED_JSON_SCHEMA, inner]
|
|
4132
4274
|
};
|
|
4133
4275
|
}
|
|
4134
4276
|
case ZodFirstPartyTypeKind.ZodReadonly: {
|
|
4135
|
-
const schema_ =
|
|
4277
|
+
const schema_ = schema__;
|
|
4136
4278
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4137
4279
|
}
|
|
4138
4280
|
case ZodFirstPartyTypeKind.ZodDefault: {
|
|
4139
|
-
const schema_ =
|
|
4281
|
+
const schema_ = schema__;
|
|
4140
4282
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4141
4283
|
}
|
|
4142
4284
|
case ZodFirstPartyTypeKind.ZodEffects: {
|
|
4143
|
-
const schema_ =
|
|
4285
|
+
const schema_ = schema__;
|
|
4144
4286
|
if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
|
|
4145
4287
|
return {};
|
|
4146
4288
|
}
|
|
4147
4289
|
return zodToJsonSchema(schema_._def.schema, childOptions);
|
|
4148
4290
|
}
|
|
4149
4291
|
case ZodFirstPartyTypeKind.ZodCatch: {
|
|
4150
|
-
const schema_ =
|
|
4292
|
+
const schema_ = schema__;
|
|
4151
4293
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4152
4294
|
}
|
|
4153
4295
|
case ZodFirstPartyTypeKind.ZodBranded: {
|
|
4154
|
-
const schema_ =
|
|
4296
|
+
const schema_ = schema__;
|
|
4155
4297
|
return zodToJsonSchema(schema_._def.type, childOptions);
|
|
4156
4298
|
}
|
|
4157
4299
|
case ZodFirstPartyTypeKind.ZodPipeline: {
|
|
4158
|
-
const schema_ =
|
|
4300
|
+
const schema_ = schema__;
|
|
4159
4301
|
return zodToJsonSchema(
|
|
4160
4302
|
childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
|
|
4161
4303
|
childOptions
|
|
4162
4304
|
);
|
|
4163
4305
|
}
|
|
4164
4306
|
case ZodFirstPartyTypeKind.ZodNullable: {
|
|
4165
|
-
const schema_ =
|
|
4307
|
+
const schema_ = schema__;
|
|
4166
4308
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4167
4309
|
return {
|
|
4168
4310
|
anyOf: [{ type: "null" }, inner]
|
|
@@ -4231,12 +4373,12 @@ async function generateOpenAPI(opts, options) {
|
|
|
4231
4373
|
if (!isContractProcedure(contract)) {
|
|
4232
4374
|
return;
|
|
4233
4375
|
}
|
|
4234
|
-
const internal = contract
|
|
4235
|
-
if (ignoreUndefinedPathProcedures && internal.path === void 0) {
|
|
4376
|
+
const internal = contract["~orpc"];
|
|
4377
|
+
if (ignoreUndefinedPathProcedures && internal.route?.path === void 0) {
|
|
4236
4378
|
return;
|
|
4237
4379
|
}
|
|
4238
|
-
const httpPath = internal.path
|
|
4239
|
-
const method = internal.method ?? "POST";
|
|
4380
|
+
const httpPath = internal.route?.path ? standardizeHTTPPath(internal.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
4381
|
+
const method = internal.route?.method ?? "POST";
|
|
4240
4382
|
let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
|
|
4241
4383
|
const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
|
|
4242
4384
|
const params = (() => {
|
|
@@ -4371,7 +4513,9 @@ async function generateOpenAPI(opts, options) {
|
|
|
4371
4513
|
};
|
|
4372
4514
|
}
|
|
4373
4515
|
return {
|
|
4374
|
-
required: Boolean(
|
|
4516
|
+
required: Boolean(
|
|
4517
|
+
internal.InputSchema && "isOptional" in internal.InputSchema && typeof internal.InputSchema.isOptional === "function" ? internal.InputSchema.isOptional() : false
|
|
4518
|
+
),
|
|
4375
4519
|
content
|
|
4376
4520
|
};
|
|
4377
4521
|
})();
|
|
@@ -4396,8 +4540,8 @@ async function generateOpenAPI(opts, options) {
|
|
|
4396
4540
|
content
|
|
4397
4541
|
};
|
|
4398
4542
|
})();
|
|
4399
|
-
if (throwOnMissingTagDefinition && internal.tags) {
|
|
4400
|
-
const missingTag = internal.tags.find((tag) => !rootTags.includes(tag));
|
|
4543
|
+
if (throwOnMissingTagDefinition && internal.route?.tags) {
|
|
4544
|
+
const missingTag = internal.route?.tags.find((tag) => !rootTags.includes(tag));
|
|
4401
4545
|
if (missingTag !== void 0) {
|
|
4402
4546
|
throw new Error(
|
|
4403
4547
|
`Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path.join(".")}]`
|
|
@@ -4405,10 +4549,10 @@ async function generateOpenAPI(opts, options) {
|
|
|
4405
4549
|
}
|
|
4406
4550
|
}
|
|
4407
4551
|
const operation = {
|
|
4408
|
-
summary: internal.summary,
|
|
4409
|
-
description: internal.description,
|
|
4410
|
-
deprecated: internal.deprecated,
|
|
4411
|
-
tags: internal.tags,
|
|
4552
|
+
summary: internal.route?.summary,
|
|
4553
|
+
description: internal.route?.description,
|
|
4554
|
+
deprecated: internal.route?.deprecated,
|
|
4555
|
+
tags: internal.route?.tags,
|
|
4412
4556
|
operationId: path.join("."),
|
|
4413
4557
|
parameters: parameters.length ? parameters : void 0,
|
|
4414
4558
|
requestBody,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
|
2
1
|
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Router } from '@orpc/server';
|
|
3
2
|
import type { FetchHandler } from '@orpc/server/fetch';
|
|
4
3
|
import type { Router as HonoRouter } from 'hono/router';
|
|
@@ -10,6 +9,5 @@ export type ResolveRouter = (router: Router<any>, method: string, pathname: stri
|
|
|
10
9
|
type Routing = HonoRouter<string[]>;
|
|
11
10
|
export declare function createOpenAPIHandler(createHonoRouter: () => Routing): FetchHandler;
|
|
12
11
|
export declare function createResolveRouter(createHonoRouter: () => Routing): ResolveRouter;
|
|
13
|
-
export declare function openAPIPathToRouterPath(path: HTTPPath): string;
|
|
14
12
|
export {};
|
|
15
13
|
//# sourceMappingURL=base-handler.d.ts.map
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE, ContractRouter, HTTPPath, WELL_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
2
2
|
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Lazy, Router } from '@orpc/server';
|
|
3
3
|
export interface EachLeafOptions {
|
|
4
|
-
router: ANY_PROCEDURE | Router<any> | ContractRouter |
|
|
4
|
+
router: ANY_PROCEDURE | Router<any> | ContractRouter | ANY_CONTRACT_PROCEDURE;
|
|
5
5
|
path: string[];
|
|
6
6
|
}
|
|
7
7
|
export interface EachLeafCallbackOptions {
|
|
@@ -13,4 +13,5 @@ export interface EachContractLeafResultItem {
|
|
|
13
13
|
path: string[];
|
|
14
14
|
}
|
|
15
15
|
export declare function eachContractProcedureLeaf(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
|
|
16
|
+
export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
16
17
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
1
2
|
import { type JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
2
|
-
import { type ZodTypeAny } from 'zod';
|
|
3
3
|
export declare const NON_LOGIC_KEYWORDS: ("$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "contentEncoding" | "contentMediaType" | "default" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly")[];
|
|
4
4
|
export declare const UNSUPPORTED_JSON_SCHEMA: {
|
|
5
5
|
not: {};
|
|
@@ -35,7 +35,7 @@ export interface ZodToJsonSchemaOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
isHandledCustomJSONSchema?: boolean;
|
|
37
37
|
}
|
|
38
|
-
export declare function zodToJsonSchema(schema:
|
|
38
|
+
export declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema, boolean>;
|
|
39
39
|
export declare function extractJSONSchema(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): {
|
|
40
40
|
schema: JSONSchema | undefined;
|
|
41
41
|
matches: JSONSchema[];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.ee0aeaf",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -34,19 +34,20 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@standard-schema/spec": "1.0.0-beta.4",
|
|
37
38
|
"escape-string-regexp": "^5.0.0",
|
|
38
39
|
"json-schema-typed": "^8.0.1",
|
|
39
40
|
"openapi3-ts": "^4.4.0",
|
|
40
|
-
"@orpc/
|
|
41
|
-
"@orpc/
|
|
42
|
-
"@orpc/
|
|
43
|
-
"@orpc/zod": "0.0.0-next.
|
|
44
|
-
"@orpc/
|
|
41
|
+
"@orpc/contract": "0.0.0-next.ee0aeaf",
|
|
42
|
+
"@orpc/server": "0.0.0-next.ee0aeaf",
|
|
43
|
+
"@orpc/transformer": "0.0.0-next.ee0aeaf",
|
|
44
|
+
"@orpc/zod": "0.0.0-next.ee0aeaf",
|
|
45
|
+
"@orpc/shared": "0.0.0-next.ee0aeaf"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@readme/openapi-parser": "^2.6.0",
|
|
48
49
|
"hono": "^4.6.12",
|
|
49
|
-
"zod": "^3.
|
|
50
|
+
"zod": "^3.24.1"
|
|
50
51
|
},
|
|
51
52
|
"scripts": {
|
|
52
53
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|