@orpc/openapi 0.0.0-next.6acfc62 → 0.0.0-next.6c13765
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-LPBZEW4B.js +165 -0
- package/dist/{chunk-HQ34JZI7.js → chunk-UU2TTVB2.js} +5 -5
- package/dist/chunk-XGHV4TH3.js +13 -0
- package/dist/fetch.js +3 -3
- package/dist/hono.js +3 -3
- package/dist/index.js +191 -36
- package/dist/next.js +3 -3
- package/dist/node.js +5 -5
- package/dist/src/adapters/fetch/openapi-handler.d.ts +3 -2
- package/dist/src/adapters/node/openapi-handler.d.ts +3 -2
- package/dist/src/adapters/standard/index.d.ts +0 -3
- package/dist/src/adapters/standard/openapi-codec.d.ts +4 -6
- package/dist/src/index.d.ts +5 -1
- package/dist/src/openapi-generator.d.ts +2 -2
- package/dist/src/openapi-operation-extender.d.ts +7 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/standard.js +4 -10
- package/package.json +8 -11
- package/dist/chunk-BHJYKXQL.js +0 -52
- package/dist/chunk-M5HOHBLW.js +0 -432
- package/dist/src/adapters/standard/bracket-notation.d.ts +0 -84
- package/dist/src/adapters/standard/openapi-serializer.d.ts +0 -11
- package/dist/src/adapters/standard/schema-coercer.d.ts +0 -10
- package/dist/src/json-serializer.d.ts +0 -5
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
standardizeHTTPPath
|
|
3
|
+
} from "./chunk-XGHV4TH3.js";
|
|
4
|
+
|
|
5
|
+
// src/adapters/standard/openapi-codec.ts
|
|
6
|
+
import { OpenAPISerializer } from "@orpc/client/openapi";
|
|
7
|
+
import { fallbackContractConfig } from "@orpc/contract";
|
|
8
|
+
import { isObject } from "@orpc/shared";
|
|
9
|
+
var OpenAPICodec = class {
|
|
10
|
+
serializer;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.serializer = options?.serializer ?? new OpenAPISerializer();
|
|
13
|
+
}
|
|
14
|
+
async decode(request, params, procedure) {
|
|
15
|
+
const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
|
|
16
|
+
if (inputStructure === "compact") {
|
|
17
|
+
const data = request.method === "GET" ? this.serializer.deserialize(request.url.searchParams) : this.serializer.deserialize(await request.body());
|
|
18
|
+
if (data === void 0) {
|
|
19
|
+
return params;
|
|
20
|
+
}
|
|
21
|
+
if (isObject(data)) {
|
|
22
|
+
return {
|
|
23
|
+
...params,
|
|
24
|
+
...data
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
const deserializeSearchParams = () => {
|
|
30
|
+
return this.serializer.deserialize(request.url.searchParams);
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
params,
|
|
34
|
+
get query() {
|
|
35
|
+
const value = deserializeSearchParams();
|
|
36
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
37
|
+
return value;
|
|
38
|
+
},
|
|
39
|
+
set query(value) {
|
|
40
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
41
|
+
},
|
|
42
|
+
headers: request.headers,
|
|
43
|
+
body: this.serializer.deserialize(await request.body())
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
encode(output, procedure) {
|
|
47
|
+
const successStatus = fallbackContractConfig("defaultSuccessStatus", procedure["~orpc"].route.successStatus);
|
|
48
|
+
const outputStructure = fallbackContractConfig("defaultOutputStructure", procedure["~orpc"].route.outputStructure);
|
|
49
|
+
if (outputStructure === "compact") {
|
|
50
|
+
return {
|
|
51
|
+
status: successStatus,
|
|
52
|
+
headers: {},
|
|
53
|
+
body: this.serializer.serialize(output)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (!isObject(output)) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
'Invalid output structure for "detailed" output. Expected format: { body: any, headers?: Record<string, string | string[] | undefined> }'
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
status: successStatus,
|
|
63
|
+
headers: output.headers ?? {},
|
|
64
|
+
body: this.serializer.serialize(output.body)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
encodeError(error) {
|
|
68
|
+
return {
|
|
69
|
+
status: error.status,
|
|
70
|
+
headers: {},
|
|
71
|
+
body: this.serializer.serialize(error.toJSON())
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/adapters/standard/openapi-matcher.ts
|
|
77
|
+
import { fallbackContractConfig as fallbackContractConfig2 } from "@orpc/contract";
|
|
78
|
+
import { convertPathToHttpPath, createContractedProcedure, eachContractProcedure, getLazyRouterPrefix, getRouterChild, isProcedure, unlazy } from "@orpc/server";
|
|
79
|
+
import { addRoute, createRouter, findRoute } from "rou3";
|
|
80
|
+
var OpenAPIMatcher = class {
|
|
81
|
+
tree = createRouter();
|
|
82
|
+
ignoreUndefinedMethod;
|
|
83
|
+
constructor(options) {
|
|
84
|
+
this.ignoreUndefinedMethod = options?.ignoreUndefinedMethod ?? false;
|
|
85
|
+
}
|
|
86
|
+
pendingRouters = [];
|
|
87
|
+
init(router, path = []) {
|
|
88
|
+
const laziedOptions = eachContractProcedure({
|
|
89
|
+
router,
|
|
90
|
+
path
|
|
91
|
+
}, ({ path: path2, contract }) => {
|
|
92
|
+
if (!contract["~orpc"].route.method && this.ignoreUndefinedMethod) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const method = fallbackContractConfig2("defaultMethod", contract["~orpc"].route.method);
|
|
96
|
+
const httpPath = contract["~orpc"].route.path ? toRou3Pattern(contract["~orpc"].route.path) : convertPathToHttpPath(path2);
|
|
97
|
+
if (isProcedure(contract)) {
|
|
98
|
+
addRoute(this.tree, method, httpPath, {
|
|
99
|
+
path: path2,
|
|
100
|
+
contract,
|
|
101
|
+
procedure: contract,
|
|
102
|
+
// this mean dev not used contract-first so we can used contract as procedure directly
|
|
103
|
+
router
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
addRoute(this.tree, method, httpPath, {
|
|
107
|
+
path: path2,
|
|
108
|
+
contract,
|
|
109
|
+
procedure: void 0,
|
|
110
|
+
router
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
|
115
|
+
...option,
|
|
116
|
+
httpPathPrefix: convertPathToHttpPath(option.path),
|
|
117
|
+
laziedPrefix: getLazyRouterPrefix(option.lazied)
|
|
118
|
+
})));
|
|
119
|
+
}
|
|
120
|
+
async match(method, pathname) {
|
|
121
|
+
if (this.pendingRouters.length) {
|
|
122
|
+
const newPendingRouters = [];
|
|
123
|
+
for (const pendingRouter of this.pendingRouters) {
|
|
124
|
+
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
|
125
|
+
const { default: router } = await unlazy(pendingRouter.lazied);
|
|
126
|
+
this.init(router, pendingRouter.path);
|
|
127
|
+
} else {
|
|
128
|
+
newPendingRouters.push(pendingRouter);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.pendingRouters = newPendingRouters;
|
|
132
|
+
}
|
|
133
|
+
const match = findRoute(this.tree, method, pathname);
|
|
134
|
+
if (!match) {
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
if (!match.data.procedure) {
|
|
138
|
+
const { default: maybeProcedure } = await unlazy(getRouterChild(match.data.router, ...match.data.path));
|
|
139
|
+
if (!isProcedure(maybeProcedure)) {
|
|
140
|
+
throw new Error(`
|
|
141
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.data.path)}.
|
|
142
|
+
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
143
|
+
`);
|
|
144
|
+
}
|
|
145
|
+
match.data.procedure = createContractedProcedure(match.data.contract, maybeProcedure);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
path: match.data.path,
|
|
149
|
+
procedure: match.data.procedure,
|
|
150
|
+
params: match.params ? decodeParams(match.params) : void 0
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
function toRou3Pattern(path) {
|
|
155
|
+
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "**:$1").replace(/\{([^}]+)\}/g, ":$1");
|
|
156
|
+
}
|
|
157
|
+
function decodeParams(params) {
|
|
158
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export {
|
|
162
|
+
OpenAPICodec,
|
|
163
|
+
OpenAPIMatcher
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=chunk-LPBZEW4B.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenAPICodec,
|
|
3
3
|
OpenAPIMatcher
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LPBZEW4B.js";
|
|
5
5
|
|
|
6
6
|
// src/adapters/fetch/openapi-handler.ts
|
|
7
|
-
import {
|
|
7
|
+
import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
|
|
8
8
|
import { StandardHandler } from "@orpc/server/standard";
|
|
9
9
|
var OpenAPIHandler = class {
|
|
10
10
|
standardHandler;
|
|
@@ -14,14 +14,14 @@ var OpenAPIHandler = class {
|
|
|
14
14
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
15
15
|
}
|
|
16
16
|
async handle(request, ...rest) {
|
|
17
|
-
const standardRequest =
|
|
17
|
+
const standardRequest = toStandardRequest(request);
|
|
18
18
|
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
19
19
|
if (!result.matched) {
|
|
20
20
|
return result;
|
|
21
21
|
}
|
|
22
22
|
return {
|
|
23
23
|
matched: true,
|
|
24
|
-
response:
|
|
24
|
+
response: toFetchResponse(result.response)
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
};
|
|
@@ -29,4 +29,4 @@ var OpenAPIHandler = class {
|
|
|
29
29
|
export {
|
|
30
30
|
OpenAPIHandler
|
|
31
31
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-UU2TTVB2.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
function standardizeHTTPPath(path) {
|
|
3
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
4
|
+
}
|
|
5
|
+
function toOpenAPI31RoutePattern(path) {
|
|
6
|
+
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "{$1}");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
standardizeHTTPPath,
|
|
11
|
+
toOpenAPI31RoutePattern
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chunk-XGHV4TH3.js.map
|
package/dist/fetch.js
CHANGED
package/dist/hono.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,53 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-
|
|
2
|
+
standardizeHTTPPath,
|
|
3
|
+
toOpenAPI31RoutePattern
|
|
4
|
+
} from "./chunk-XGHV4TH3.js";
|
|
5
|
+
|
|
6
|
+
// src/openapi-operation-extender.ts
|
|
7
|
+
import { isProcedure } from "@orpc/server";
|
|
8
|
+
var OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
|
9
|
+
function setOperationExtender(o, extend) {
|
|
10
|
+
return new Proxy(o, {
|
|
11
|
+
get(target, prop, receiver) {
|
|
12
|
+
if (prop === OPERATION_EXTENDER_SYMBOL) {
|
|
13
|
+
return extend;
|
|
14
|
+
}
|
|
15
|
+
return Reflect.get(target, prop, receiver);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function getOperationExtender(o) {
|
|
20
|
+
return o[OPERATION_EXTENDER_SYMBOL];
|
|
21
|
+
}
|
|
22
|
+
function extendOperation(operation, procedure) {
|
|
23
|
+
const operationExtenders = [];
|
|
24
|
+
for (const errorItem of Object.values(procedure["~orpc"].errorMap)) {
|
|
25
|
+
const maybeExtender = getOperationExtender(errorItem);
|
|
26
|
+
if (maybeExtender) {
|
|
27
|
+
operationExtenders.push(maybeExtender);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (isProcedure(procedure)) {
|
|
31
|
+
for (const middleware of procedure["~orpc"].middlewares) {
|
|
32
|
+
const maybeExtender = getOperationExtender(middleware);
|
|
33
|
+
if (maybeExtender) {
|
|
34
|
+
operationExtenders.push(maybeExtender);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
let currentOperation = operation;
|
|
39
|
+
for (const extender of operationExtenders) {
|
|
40
|
+
if (typeof extender === "function") {
|
|
41
|
+
currentOperation = extender(currentOperation, procedure);
|
|
42
|
+
} else {
|
|
43
|
+
currentOperation = {
|
|
44
|
+
...currentOperation,
|
|
45
|
+
...extender
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return currentOperation;
|
|
50
|
+
}
|
|
5
51
|
|
|
6
52
|
// src/openapi.ts
|
|
7
53
|
import { OpenApiBuilder } from "openapi3-ts/oas31";
|
|
@@ -34,7 +80,9 @@ var OpenAPIContentBuilder = class {
|
|
|
34
80
|
};
|
|
35
81
|
|
|
36
82
|
// src/openapi-generator.ts
|
|
37
|
-
import {
|
|
83
|
+
import { fallbackORPCErrorStatus } from "@orpc/client";
|
|
84
|
+
import { OpenAPIJsonSerializer } from "@orpc/client/openapi";
|
|
85
|
+
import { fallbackContractConfig as fallbackContractConfig2, getEventIteratorSchemaDetails } from "@orpc/contract";
|
|
38
86
|
import { eachAllContractProcedure } from "@orpc/server";
|
|
39
87
|
import { group } from "@orpc/shared";
|
|
40
88
|
|
|
@@ -183,14 +231,14 @@ var OpenAPIOutputStructureParser = class {
|
|
|
183
231
|
};
|
|
184
232
|
|
|
185
233
|
// src/openapi-parameters-builder.ts
|
|
186
|
-
import { get,
|
|
234
|
+
import { get, isObject, omit } from "@orpc/shared";
|
|
187
235
|
var OpenAPIParametersBuilder = class {
|
|
188
236
|
build(paramIn, jsonSchema, options) {
|
|
189
237
|
const parameters = [];
|
|
190
238
|
for (const name in jsonSchema.properties) {
|
|
191
239
|
const schema = jsonSchema.properties[name];
|
|
192
240
|
const paramExamples = jsonSchema.examples?.filter((example) => {
|
|
193
|
-
return
|
|
241
|
+
return isObject(example) && name in example;
|
|
194
242
|
}).map((example) => {
|
|
195
243
|
return example[name];
|
|
196
244
|
});
|
|
@@ -251,7 +299,7 @@ var CompositeSchemaConverter = class {
|
|
|
251
299
|
};
|
|
252
300
|
|
|
253
301
|
// src/schema-utils.ts
|
|
254
|
-
import {
|
|
302
|
+
import { isObject as isObject2 } from "@orpc/shared";
|
|
255
303
|
|
|
256
304
|
// src/schema.ts
|
|
257
305
|
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
|
@@ -287,10 +335,10 @@ var NON_LOGIC_KEYWORDS = [
|
|
|
287
335
|
// src/schema-utils.ts
|
|
288
336
|
var SchemaUtils = class {
|
|
289
337
|
isFileSchema(schema) {
|
|
290
|
-
return
|
|
338
|
+
return isObject2(schema) && schema.type === "string" && typeof schema.contentMediaType === "string";
|
|
291
339
|
}
|
|
292
340
|
isObjectSchema(schema) {
|
|
293
|
-
return
|
|
341
|
+
return isObject2(schema) && schema.type === "object";
|
|
294
342
|
}
|
|
295
343
|
isAnySchema(schema) {
|
|
296
344
|
return schema === true || Object.keys(schema).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
|
|
@@ -313,7 +361,7 @@ var SchemaUtils = class {
|
|
|
313
361
|
}, {});
|
|
314
362
|
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
315
363
|
matched.examples = schema.examples?.map((example) => {
|
|
316
|
-
if (!
|
|
364
|
+
if (!isObject2(example)) {
|
|
317
365
|
return example;
|
|
318
366
|
}
|
|
319
367
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -329,7 +377,7 @@ var SchemaUtils = class {
|
|
|
329
377
|
}, {});
|
|
330
378
|
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
331
379
|
rest.examples = schema.examples?.map((example) => {
|
|
332
|
-
if (!
|
|
380
|
+
if (!isObject2(example)) {
|
|
333
381
|
return example;
|
|
334
382
|
}
|
|
335
383
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -389,7 +437,7 @@ var OpenAPIGenerator = class {
|
|
|
389
437
|
this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
|
|
390
438
|
this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
|
|
391
439
|
this.schemaUtils = options?.schemaUtils ?? new SchemaUtils();
|
|
392
|
-
this.jsonSerializer = options?.jsonSerializer ?? new
|
|
440
|
+
this.jsonSerializer = options?.jsonSerializer ?? new OpenAPIJsonSerializer();
|
|
393
441
|
this.contentBuilder = options?.contentBuilder ?? new OpenAPIContentBuilder(this.schemaUtils);
|
|
394
442
|
this.pathParser = new OpenAPIPathParser();
|
|
395
443
|
this.inputStructureParser = options?.inputStructureParser ?? new OpenAPIInputStructureParser(this.schemaConverter, this.schemaUtils, this.pathParser);
|
|
@@ -415,27 +463,124 @@ var OpenAPIGenerator = class {
|
|
|
415
463
|
return;
|
|
416
464
|
}
|
|
417
465
|
const method = fallbackContractConfig2("defaultMethod", def.route?.method);
|
|
418
|
-
const httpPath = def.route?.path ?
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
466
|
+
const httpPath = def.route?.path ? toOpenAPI31RoutePattern(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
467
|
+
const { parameters, requestBody } = (() => {
|
|
468
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.inputSchema);
|
|
469
|
+
if (eventIteratorSchemaDetails) {
|
|
470
|
+
const requestBody3 = {
|
|
471
|
+
required: true,
|
|
472
|
+
content: {
|
|
473
|
+
"text/event-stream": {
|
|
474
|
+
schema: {
|
|
475
|
+
oneOf: [
|
|
476
|
+
{
|
|
477
|
+
type: "object",
|
|
478
|
+
properties: {
|
|
479
|
+
event: { type: "string", const: "message" },
|
|
480
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
|
|
481
|
+
id: { type: "string" },
|
|
482
|
+
retry: { type: "number" }
|
|
483
|
+
},
|
|
484
|
+
required: ["event", "data"]
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
type: "object",
|
|
488
|
+
properties: {
|
|
489
|
+
event: { type: "string", const: "done" },
|
|
490
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
|
|
491
|
+
id: { type: "string" },
|
|
492
|
+
retry: { type: "number" }
|
|
493
|
+
},
|
|
494
|
+
required: ["event", "data"]
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
type: "object",
|
|
498
|
+
properties: {
|
|
499
|
+
event: { type: "string", const: "error" },
|
|
500
|
+
data: {},
|
|
501
|
+
id: { type: "string" },
|
|
502
|
+
retry: { type: "number" }
|
|
503
|
+
},
|
|
504
|
+
required: ["event", "data"]
|
|
505
|
+
}
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
return { requestBody: requestBody3, parameters: [] };
|
|
512
|
+
}
|
|
513
|
+
const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
|
|
514
|
+
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
|
515
|
+
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
516
|
+
required: true
|
|
517
|
+
}) : [];
|
|
518
|
+
const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
|
|
519
|
+
const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
|
|
520
|
+
const parameters2 = [...params, ...query, ...headers];
|
|
521
|
+
const requestBody2 = bodySchema !== void 0 ? {
|
|
522
|
+
required: this.schemaUtils.isUndefinableSchema(bodySchema),
|
|
523
|
+
content: this.contentBuilder.build(bodySchema)
|
|
524
|
+
} : void 0;
|
|
525
|
+
return { parameters: parameters2, requestBody: requestBody2 };
|
|
526
|
+
})();
|
|
527
|
+
const { responses } = (() => {
|
|
528
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.outputSchema);
|
|
529
|
+
if (eventIteratorSchemaDetails) {
|
|
530
|
+
const responses3 = {};
|
|
531
|
+
responses3[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
532
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
533
|
+
content: {
|
|
534
|
+
"text/event-stream": {
|
|
535
|
+
schema: {
|
|
536
|
+
oneOf: [
|
|
537
|
+
{
|
|
538
|
+
type: "object",
|
|
539
|
+
properties: {
|
|
540
|
+
event: { type: "string", const: "message" },
|
|
541
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
|
|
542
|
+
id: { type: "string" },
|
|
543
|
+
retry: { type: "number" }
|
|
544
|
+
},
|
|
545
|
+
required: ["event", "data"]
|
|
546
|
+
},
|
|
547
|
+
{
|
|
548
|
+
type: "object",
|
|
549
|
+
properties: {
|
|
550
|
+
event: { type: "string", const: "done" },
|
|
551
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
|
|
552
|
+
id: { type: "string" },
|
|
553
|
+
retry: { type: "number" }
|
|
554
|
+
},
|
|
555
|
+
required: ["event", "data"]
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
type: "object",
|
|
559
|
+
properties: {
|
|
560
|
+
event: { type: "string", const: "error" },
|
|
561
|
+
data: {},
|
|
562
|
+
id: { type: "string" },
|
|
563
|
+
retry: { type: "number" }
|
|
564
|
+
},
|
|
565
|
+
required: ["event", "data"]
|
|
566
|
+
}
|
|
567
|
+
]
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
return { responses: responses3 };
|
|
573
|
+
}
|
|
574
|
+
const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
|
|
575
|
+
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
|
576
|
+
const responses2 = {};
|
|
577
|
+
responses2[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
578
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
579
|
+
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
|
|
580
|
+
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
|
|
581
|
+
};
|
|
582
|
+
return { responses: responses2 };
|
|
583
|
+
})();
|
|
439
584
|
const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
|
|
440
585
|
...config,
|
|
441
586
|
code,
|
|
@@ -506,8 +651,9 @@ var OpenAPIGenerator = class {
|
|
|
506
651
|
requestBody,
|
|
507
652
|
responses
|
|
508
653
|
};
|
|
654
|
+
const extendedOperation = extendOperation(operation, contract);
|
|
509
655
|
builder.addPath(httpPath, {
|
|
510
|
-
[method.toLocaleLowerCase()]:
|
|
656
|
+
[method.toLocaleLowerCase()]: extendedOperation
|
|
511
657
|
});
|
|
512
658
|
} catch (e) {
|
|
513
659
|
if (e instanceof OpenAPIError) {
|
|
@@ -529,11 +675,15 @@ var OpenAPIGenerator = class {
|
|
|
529
675
|
return this.jsonSerializer.serialize(builder.getSpec());
|
|
530
676
|
}
|
|
531
677
|
};
|
|
678
|
+
|
|
679
|
+
// src/index.ts
|
|
680
|
+
var oo = {
|
|
681
|
+
spec: setOperationExtender
|
|
682
|
+
};
|
|
532
683
|
export {
|
|
533
684
|
CompositeSchemaConverter,
|
|
534
685
|
JSONSchema,
|
|
535
686
|
Format as JSONSchemaFormat,
|
|
536
|
-
JSONSerializer,
|
|
537
687
|
NON_LOGIC_KEYWORDS,
|
|
538
688
|
OpenAPIContentBuilder,
|
|
539
689
|
OpenAPIGenerator,
|
|
@@ -541,6 +691,11 @@ export {
|
|
|
541
691
|
OpenAPIPathParser,
|
|
542
692
|
OpenApiBuilder,
|
|
543
693
|
SchemaUtils,
|
|
544
|
-
|
|
694
|
+
extendOperation,
|
|
695
|
+
getOperationExtender,
|
|
696
|
+
oo,
|
|
697
|
+
setOperationExtender,
|
|
698
|
+
standardizeHTTPPath,
|
|
699
|
+
toOpenAPI31RoutePattern
|
|
545
700
|
};
|
|
546
701
|
//# sourceMappingURL=index.js.map
|
package/dist/next.js
CHANGED
package/dist/node.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenAPICodec,
|
|
3
3
|
OpenAPIMatcher
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-LPBZEW4B.js";
|
|
5
|
+
import "./chunk-XGHV4TH3.js";
|
|
6
6
|
|
|
7
7
|
// src/adapters/node/openapi-handler.ts
|
|
8
|
-
import {
|
|
8
|
+
import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
|
|
9
9
|
import { StandardHandler } from "@orpc/server/standard";
|
|
10
10
|
var OpenAPIHandler = class {
|
|
11
11
|
standardHandler;
|
|
@@ -15,12 +15,12 @@ var OpenAPIHandler = class {
|
|
|
15
15
|
this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
|
|
16
16
|
}
|
|
17
17
|
async handle(req, res, ...rest) {
|
|
18
|
-
const standardRequest =
|
|
18
|
+
const standardRequest = toStandardRequest(req, res);
|
|
19
19
|
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
20
20
|
if (!result.matched) {
|
|
21
21
|
return { matched: false };
|
|
22
22
|
}
|
|
23
|
-
await
|
|
23
|
+
await sendStandardResponse(res, result.response);
|
|
24
24
|
return { matched: true };
|
|
25
25
|
}
|
|
26
26
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Context, Router } from '@orpc/server';
|
|
2
2
|
import type { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
|
3
|
-
import type {
|
|
3
|
+
import type { StandardHandleOptions } from '@orpc/server/standard';
|
|
4
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
|
4
5
|
import type { OpenAPIHandlerOptions } from '../standard';
|
|
5
6
|
export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
|
6
7
|
private readonly standardHandler;
|
|
7
8
|
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
8
|
-
handle(request: Request, ...rest:
|
|
9
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Context, Router } from '@orpc/server';
|
|
2
2
|
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from '@orpc/server/node';
|
|
3
|
-
import type {
|
|
3
|
+
import type { StandardHandleOptions } from '@orpc/server/standard';
|
|
4
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
|
4
5
|
import type { OpenAPIHandlerOptions } from '../standard';
|
|
5
6
|
export declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
|
6
7
|
private readonly standardHandler;
|
|
7
8
|
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
8
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest:
|
|
9
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * as BracketNotation from './bracket-notation';
|
|
2
1
|
export * from './openapi-codec';
|
|
3
2
|
export * from './openapi-handler';
|
|
4
3
|
export * from './openapi-matcher';
|
|
5
|
-
export * from './openapi-serializer';
|
|
6
|
-
export * from './schema-coercer';
|
|
7
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
+
import type { ORPCError } from '@orpc/client';
|
|
1
2
|
import type { AnyProcedure } from '@orpc/server';
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import { OpenAPISerializer } from '
|
|
5
|
-
import { type SchemaCoercer } from './schema-coercer';
|
|
3
|
+
import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
|
|
4
|
+
import type { StandardCodec, StandardParams } from '@orpc/server/standard';
|
|
5
|
+
import { OpenAPISerializer } from '@orpc/client/openapi';
|
|
6
6
|
export interface OpenAPICodecOptions {
|
|
7
7
|
serializer?: OpenAPISerializer;
|
|
8
|
-
schemaCoercers?: SchemaCoercer[];
|
|
9
8
|
}
|
|
10
9
|
export declare class OpenAPICodec implements StandardCodec {
|
|
11
10
|
private readonly serializer;
|
|
12
|
-
private readonly compositeSchemaCoercer;
|
|
13
11
|
constructor(options?: OpenAPICodecOptions);
|
|
14
12
|
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
15
13
|
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|