@orpc/openapi 0.46.0 → 1.0.0-beta.1
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/README.md +3 -1
- package/dist/adapters/fetch/index.d.mts +3 -2
- package/dist/adapters/fetch/index.d.ts +3 -2
- package/dist/adapters/fetch/index.mjs +5 -4
- package/dist/adapters/hono/index.d.mts +2 -1
- package/dist/adapters/hono/index.d.ts +2 -1
- package/dist/adapters/hono/index.mjs +5 -4
- package/dist/adapters/next/index.d.mts +2 -1
- package/dist/adapters/next/index.d.ts +2 -1
- package/dist/adapters/next/index.mjs +5 -4
- package/dist/adapters/node/index.d.mts +3 -2
- package/dist/adapters/node/index.d.ts +3 -2
- package/dist/adapters/node/index.mjs +12 -8
- package/dist/adapters/standard/index.d.mts +18 -7
- package/dist/adapters/standard/index.d.ts +18 -7
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +91 -140
- package/dist/index.d.ts +91 -140
- package/dist/index.mjs +225 -583
- package/dist/shared/{openapi.CDsfPHgw.mjs → openapi.BNHmrMe2.mjs} +21 -24
- package/dist/shared/openapi.DZzpQAb-.mjs +231 -0
- package/dist/shared/openapi.Dv-KT_Bx.mjs +33 -0
- package/dist/shared/openapi.IfmmOyba.d.mts +8 -0
- package/dist/shared/openapi.IfmmOyba.d.ts +8 -0
- package/package.json +11 -11
- package/dist/shared/openapi.BHG_gu5Z.mjs +0 -8
- package/dist/shared/openapi.BcJH4F9P.mjs +0 -27
- package/dist/shared/openapi.Dz_6xooR.d.mts +0 -7
- package/dist/shared/openapi.Dz_6xooR.d.ts +0 -7
@@ -1,12 +1,11 @@
|
|
1
1
|
import { fallbackContractConfig } from '@orpc/contract';
|
2
|
-
import { OpenAPISerializer } from '@orpc/openapi-client/standard';
|
3
2
|
import { isObject } from '@orpc/shared';
|
4
|
-
import {
|
3
|
+
import { traverseContractProcedures, toHttpPath, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
5
4
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
6
|
-
import { s as standardizeHTTPPath } from './openapi.
|
5
|
+
import { s as standardizeHTTPPath } from './openapi.DZzpQAb-.mjs';
|
7
6
|
|
8
|
-
class
|
9
|
-
constructor(serializer
|
7
|
+
class StandardOpenAPICodec {
|
8
|
+
constructor(serializer) {
|
10
9
|
this.serializer = serializer;
|
11
10
|
}
|
12
11
|
async decode(request, params, procedure) {
|
@@ -71,16 +70,20 @@ class OpenAPICodec {
|
|
71
70
|
}
|
72
71
|
}
|
73
72
|
|
74
|
-
|
73
|
+
function toRou3Pattern(path) {
|
74
|
+
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
75
|
+
}
|
76
|
+
function decodeParams(params) {
|
77
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
|
78
|
+
}
|
79
|
+
|
80
|
+
class StandardOpenAPIMatcher {
|
75
81
|
tree = createRouter();
|
76
82
|
pendingRouters = [];
|
77
83
|
init(router, path = []) {
|
78
|
-
const laziedOptions =
|
79
|
-
router,
|
80
|
-
path
|
81
|
-
}, ({ path: path2, contract }) => {
|
84
|
+
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
82
85
|
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
83
|
-
const httpPath =
|
86
|
+
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
84
87
|
if (isProcedure(contract)) {
|
85
88
|
addRoute(this.tree, method, httpPath, {
|
86
89
|
path: path2,
|
@@ -100,8 +103,8 @@ class OpenAPIMatcher {
|
|
100
103
|
});
|
101
104
|
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
102
105
|
...option,
|
103
|
-
httpPathPrefix:
|
104
|
-
laziedPrefix:
|
106
|
+
httpPathPrefix: toHttpPath(option.path),
|
107
|
+
laziedPrefix: getLazyMeta(option.router).prefix
|
105
108
|
})));
|
106
109
|
}
|
107
110
|
async match(method, pathname) {
|
@@ -109,7 +112,7 @@ class OpenAPIMatcher {
|
|
109
112
|
const newPendingRouters = [];
|
110
113
|
for (const pendingRouter of this.pendingRouters) {
|
111
114
|
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
112
|
-
const { default: router } = await unlazy(pendingRouter.
|
115
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
113
116
|
this.init(router, pendingRouter.path);
|
114
117
|
} else {
|
115
118
|
newPendingRouters.push(pendingRouter);
|
@@ -122,14 +125,14 @@ class OpenAPIMatcher {
|
|
122
125
|
return void 0;
|
123
126
|
}
|
124
127
|
if (!match.data.procedure) {
|
125
|
-
const { default: maybeProcedure } = await unlazy(
|
128
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
|
126
129
|
if (!isProcedure(maybeProcedure)) {
|
127
130
|
throw new Error(`
|
128
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${
|
131
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
|
129
132
|
Ensure that the procedure is correctly defined and matches the expected contract.
|
130
133
|
`);
|
131
134
|
}
|
132
|
-
match.data.procedure = createContractedProcedure(match.data.contract
|
135
|
+
match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
|
133
136
|
}
|
134
137
|
return {
|
135
138
|
path: match.data.path,
|
@@ -138,11 +141,5 @@ class OpenAPIMatcher {
|
|
138
141
|
};
|
139
142
|
}
|
140
143
|
}
|
141
|
-
function toRou3Pattern(path) {
|
142
|
-
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "**:$1").replace(/\{([^}]+)\}/g, ":$1");
|
143
|
-
}
|
144
|
-
function decodeParams(params) {
|
145
|
-
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
|
146
|
-
}
|
147
144
|
|
148
|
-
export {
|
145
|
+
export { StandardOpenAPICodec as S, StandardOpenAPIMatcher as a, decodeParams as d, toRou3Pattern as t };
|
@@ -0,0 +1,231 @@
|
|
1
|
+
import { isObject, findDeepMatches } from '@orpc/shared';
|
2
|
+
import 'json-schema-typed/draft-2020-12';
|
3
|
+
|
4
|
+
const LOGIC_KEYWORDS = [
|
5
|
+
"$dynamicRef",
|
6
|
+
"$ref",
|
7
|
+
"additionalItems",
|
8
|
+
"additionalProperties",
|
9
|
+
"allOf",
|
10
|
+
"anyOf",
|
11
|
+
"const",
|
12
|
+
"contains",
|
13
|
+
"contentEncoding",
|
14
|
+
"contentMediaType",
|
15
|
+
"contentSchema",
|
16
|
+
"dependencies",
|
17
|
+
"dependentRequired",
|
18
|
+
"dependentSchemas",
|
19
|
+
"else",
|
20
|
+
"enum",
|
21
|
+
"exclusiveMaximum",
|
22
|
+
"exclusiveMinimum",
|
23
|
+
"format",
|
24
|
+
"if",
|
25
|
+
"items",
|
26
|
+
"maxContains",
|
27
|
+
"maximum",
|
28
|
+
"maxItems",
|
29
|
+
"maxLength",
|
30
|
+
"maxProperties",
|
31
|
+
"minContains",
|
32
|
+
"minimum",
|
33
|
+
"minItems",
|
34
|
+
"minLength",
|
35
|
+
"minProperties",
|
36
|
+
"multipleOf",
|
37
|
+
"not",
|
38
|
+
"oneOf",
|
39
|
+
"pattern",
|
40
|
+
"patternProperties",
|
41
|
+
"prefixItems",
|
42
|
+
"properties",
|
43
|
+
"propertyNames",
|
44
|
+
"required",
|
45
|
+
"then",
|
46
|
+
"type",
|
47
|
+
"unevaluatedItems",
|
48
|
+
"unevaluatedProperties",
|
49
|
+
"uniqueItems"
|
50
|
+
];
|
51
|
+
|
52
|
+
function isFileSchema(schema) {
|
53
|
+
return isObject(schema) && schema.type === "string" && typeof schema.contentMediaType === "string";
|
54
|
+
}
|
55
|
+
function isObjectSchema(schema) {
|
56
|
+
return isObject(schema) && schema.type === "object";
|
57
|
+
}
|
58
|
+
function isAnySchema(schema) {
|
59
|
+
if (schema === true) {
|
60
|
+
return true;
|
61
|
+
}
|
62
|
+
if (Object.keys(schema).every((k) => !LOGIC_KEYWORDS.includes(k))) {
|
63
|
+
return true;
|
64
|
+
}
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
function separateObjectSchema(schema, separatedProperties) {
|
68
|
+
if (Object.keys(schema).some((k) => k !== "type" && k !== "properties" && k !== "required" && LOGIC_KEYWORDS.includes(k))) {
|
69
|
+
return [{ type: "object" }, schema];
|
70
|
+
}
|
71
|
+
const matched = { ...schema };
|
72
|
+
const rest = { ...schema };
|
73
|
+
matched.properties = schema.properties && Object.entries(schema.properties).filter(([key]) => separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
74
|
+
acc[key] = value;
|
75
|
+
return acc;
|
76
|
+
}, {});
|
77
|
+
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
78
|
+
matched.examples = schema.examples?.map((example) => {
|
79
|
+
if (!isObject(example)) {
|
80
|
+
return example;
|
81
|
+
}
|
82
|
+
return Object.entries(example).reduce((acc, [key, value]) => {
|
83
|
+
if (separatedProperties.includes(key)) {
|
84
|
+
acc[key] = value;
|
85
|
+
}
|
86
|
+
return acc;
|
87
|
+
}, {});
|
88
|
+
});
|
89
|
+
rest.properties = schema.properties && Object.entries(schema.properties).filter(([key]) => !separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
90
|
+
acc[key] = value;
|
91
|
+
return acc;
|
92
|
+
}, {});
|
93
|
+
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
94
|
+
rest.examples = schema.examples?.map((example) => {
|
95
|
+
if (!isObject(example)) {
|
96
|
+
return example;
|
97
|
+
}
|
98
|
+
return Object.entries(example).reduce((acc, [key, value]) => {
|
99
|
+
if (!separatedProperties.includes(key)) {
|
100
|
+
acc[key] = value;
|
101
|
+
}
|
102
|
+
return acc;
|
103
|
+
}, {});
|
104
|
+
});
|
105
|
+
return [matched, rest];
|
106
|
+
}
|
107
|
+
function filterSchemaBranches(schema, check, matches = []) {
|
108
|
+
if (check(schema)) {
|
109
|
+
matches.push(schema);
|
110
|
+
return [matches, void 0];
|
111
|
+
}
|
112
|
+
if (isObject(schema)) {
|
113
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
114
|
+
if (schema[keyword] && Object.keys(schema).every(
|
115
|
+
(k) => k === keyword || !LOGIC_KEYWORDS.includes(k)
|
116
|
+
)) {
|
117
|
+
const rest = schema[keyword].map((s) => filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
|
118
|
+
if (rest.length === 1 && typeof rest[0] === "object") {
|
119
|
+
return [matches, { ...schema, [keyword]: void 0, ...rest[0] }];
|
120
|
+
}
|
121
|
+
return [matches, { ...schema, [keyword]: rest }];
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return [matches, schema];
|
126
|
+
}
|
127
|
+
|
128
|
+
function standardizeHTTPPath(path) {
|
129
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
130
|
+
}
|
131
|
+
function toOpenAPIPath(path) {
|
132
|
+
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/{$1}");
|
133
|
+
}
|
134
|
+
function toOpenAPIMethod(method) {
|
135
|
+
return method.toLocaleLowerCase();
|
136
|
+
}
|
137
|
+
function getDynamicParams(path) {
|
138
|
+
return path ? standardizeHTTPPath(path).match(/\/\{([^}]+)\}/g)?.map((v) => v.match(/\{\+?([^}]+)\}/)[1]) : void 0;
|
139
|
+
}
|
140
|
+
function toOpenAPIContent(schema) {
|
141
|
+
const content = {};
|
142
|
+
const [matches, restSchema] = filterSchemaBranches(schema, isFileSchema);
|
143
|
+
for (const file of matches) {
|
144
|
+
content[file.contentMediaType] = {
|
145
|
+
schema: toOpenAPISchema(file)
|
146
|
+
};
|
147
|
+
}
|
148
|
+
if (restSchema !== void 0) {
|
149
|
+
content["application/json"] = {
|
150
|
+
schema: toOpenAPISchema(restSchema)
|
151
|
+
};
|
152
|
+
const isStillHasFileSchema = findDeepMatches((v) => isObject(v) && isFileSchema(v), restSchema).values.length > 0;
|
153
|
+
if (isStillHasFileSchema) {
|
154
|
+
content["multipart/form-data"] = {
|
155
|
+
schema: toOpenAPISchema(restSchema)
|
156
|
+
};
|
157
|
+
}
|
158
|
+
}
|
159
|
+
return content;
|
160
|
+
}
|
161
|
+
function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema], [returnsRequired, returnsSchema]) {
|
162
|
+
return {
|
163
|
+
"text/event-stream": {
|
164
|
+
schema: toOpenAPISchema({
|
165
|
+
oneOf: [
|
166
|
+
{
|
167
|
+
type: "object",
|
168
|
+
properties: {
|
169
|
+
event: { const: "message" },
|
170
|
+
data: yieldsSchema,
|
171
|
+
id: { type: "string" },
|
172
|
+
retry: { type: "number" }
|
173
|
+
},
|
174
|
+
required: yieldsRequired ? ["event", "data"] : ["event"]
|
175
|
+
},
|
176
|
+
{
|
177
|
+
type: "object",
|
178
|
+
properties: {
|
179
|
+
event: { const: "done" },
|
180
|
+
data: returnsSchema,
|
181
|
+
id: { type: "string" },
|
182
|
+
retry: { type: "number" }
|
183
|
+
},
|
184
|
+
required: returnsRequired ? ["event", "data"] : ["event"]
|
185
|
+
},
|
186
|
+
{
|
187
|
+
type: "object",
|
188
|
+
properties: {
|
189
|
+
event: { const: "error" },
|
190
|
+
data: {},
|
191
|
+
id: { type: "string" },
|
192
|
+
retry: { type: "number" }
|
193
|
+
},
|
194
|
+
required: ["event"]
|
195
|
+
}
|
196
|
+
]
|
197
|
+
})
|
198
|
+
}
|
199
|
+
};
|
200
|
+
}
|
201
|
+
function toOpenAPIParameters(schema, parameterIn) {
|
202
|
+
const parameters = [];
|
203
|
+
for (const key in schema.properties) {
|
204
|
+
const keySchema = schema.properties[key];
|
205
|
+
parameters.push({
|
206
|
+
name: key,
|
207
|
+
in: parameterIn,
|
208
|
+
required: schema.required?.includes(key),
|
209
|
+
style: parameterIn === "query" ? "deepObject" : void 0,
|
210
|
+
explode: parameterIn === "query" ? true : void 0,
|
211
|
+
schema: toOpenAPISchema(keySchema)
|
212
|
+
});
|
213
|
+
}
|
214
|
+
return parameters;
|
215
|
+
}
|
216
|
+
function checkParamsSchema(schema, params) {
|
217
|
+
const properties = Object.keys(schema.properties ?? {});
|
218
|
+
const required = schema.required ?? [];
|
219
|
+
if (properties.length !== params.length || properties.some((v) => !params.includes(v))) {
|
220
|
+
return false;
|
221
|
+
}
|
222
|
+
if (required.length !== params.length || required.some((v) => !params.includes(v))) {
|
223
|
+
return false;
|
224
|
+
}
|
225
|
+
return true;
|
226
|
+
}
|
227
|
+
function toOpenAPISchema(schema) {
|
228
|
+
return schema === true ? {} : schema === false ? { not: {} } : schema;
|
229
|
+
}
|
230
|
+
|
231
|
+
export { LOGIC_KEYWORDS as L, toOpenAPIPath as a, toOpenAPIEventIteratorContent as b, isObjectSchema as c, separateObjectSchema as d, checkParamsSchema as e, toOpenAPIParameters as f, getDynamicParams as g, toOpenAPIContent as h, isAnySchema as i, toOpenAPISchema as j, isFileSchema as k, filterSchemaBranches as l, standardizeHTTPPath as s, toOpenAPIMethod as t };
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
2
|
+
import { StandardHandler } from '@orpc/server/standard';
|
3
|
+
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
4
|
+
import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from './openapi.BNHmrMe2.mjs';
|
5
|
+
import '@orpc/shared';
|
6
|
+
import 'json-schema-typed/draft-2020-12';
|
7
|
+
|
8
|
+
class OpenAPIHandler {
|
9
|
+
standardHandler;
|
10
|
+
constructor(router, options = {}) {
|
11
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
12
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
13
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
14
|
+
const matcher = new StandardOpenAPIMatcher();
|
15
|
+
const codec = new StandardOpenAPICodec(serializer);
|
16
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
17
|
+
}
|
18
|
+
async handle(request, ...[
|
19
|
+
options = {}
|
20
|
+
]) {
|
21
|
+
const standardRequest = toStandardLazyRequest(request);
|
22
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
23
|
+
if (!result.matched) {
|
24
|
+
return result;
|
25
|
+
}
|
26
|
+
return {
|
27
|
+
matched: true,
|
28
|
+
response: toFetchResponse(result.response, options)
|
29
|
+
};
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
export { OpenAPIHandler as O };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
2
|
+
import { Context } from '@orpc/server';
|
3
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
|
+
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardOpenAPIHandlerOptions as S };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
2
|
+
import { Context } from '@orpc/server';
|
3
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
|
+
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardOpenAPIHandlerOptions as S };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/openapi",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "1.0.0-beta.1",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -50,19 +50,19 @@
|
|
50
50
|
],
|
51
51
|
"dependencies": {
|
52
52
|
"json-schema-typed": "^8.0.1",
|
53
|
-
"
|
53
|
+
"openapi-types": "^12.1.3",
|
54
54
|
"rou3": "^0.5.1",
|
55
|
-
"@orpc/client": "0.
|
56
|
-
"@orpc/
|
57
|
-
"@orpc/
|
58
|
-
"@orpc/
|
59
|
-
"@orpc/
|
60
|
-
"@orpc/standard-server": "0.
|
61
|
-
"@orpc/standard-server-fetch": "0.
|
62
|
-
"@orpc/standard-server-node": "0.
|
55
|
+
"@orpc/openapi-client": "1.0.0-beta.1",
|
56
|
+
"@orpc/server": "1.0.0-beta.1",
|
57
|
+
"@orpc/contract": "1.0.0-beta.1",
|
58
|
+
"@orpc/client": "1.0.0-beta.1",
|
59
|
+
"@orpc/shared": "1.0.0-beta.1",
|
60
|
+
"@orpc/standard-server": "1.0.0-beta.1",
|
61
|
+
"@orpc/standard-server-fetch": "1.0.0-beta.1",
|
62
|
+
"@orpc/standard-server-node": "1.0.0-beta.1"
|
63
63
|
},
|
64
64
|
"devDependencies": {
|
65
|
-
"zod": "^3.24.
|
65
|
+
"zod": "^3.24.2"
|
66
66
|
},
|
67
67
|
"scripts": {
|
68
68
|
"build": "unbuild",
|
@@ -1,8 +0,0 @@
|
|
1
|
-
function standardizeHTTPPath(path) {
|
2
|
-
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
3
|
-
}
|
4
|
-
function toOpenAPI31RoutePattern(path) {
|
5
|
-
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "{$1}");
|
6
|
-
}
|
7
|
-
|
8
|
-
export { standardizeHTTPPath as s, toOpenAPI31RoutePattern as t };
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import { StandardHandler } from '@orpc/server/standard';
|
2
|
-
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
-
import { a as OpenAPIMatcher, O as OpenAPICodec } from './openapi.CDsfPHgw.mjs';
|
4
|
-
|
5
|
-
class OpenAPIHandler {
|
6
|
-
standardHandler;
|
7
|
-
constructor(router, options) {
|
8
|
-
const matcher = options?.matcher ?? new OpenAPIMatcher();
|
9
|
-
const codec = options?.codec ?? new OpenAPICodec();
|
10
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
11
|
-
}
|
12
|
-
async handle(request, ...[
|
13
|
-
options = {}
|
14
|
-
]) {
|
15
|
-
const standardRequest = toStandardLazyRequest(request);
|
16
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
17
|
-
if (!result.matched) {
|
18
|
-
return result;
|
19
|
-
}
|
20
|
-
return {
|
21
|
-
matched: true,
|
22
|
-
response: toFetchResponse(result.response, options)
|
23
|
-
};
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
export { OpenAPIHandler as O };
|